Acquire on a separate thread

Questions, comments and suggestions concerning VintaSoft Twain .NET SDK.

Moderator: Alex

Post Reply
EbenRoux
Posts: 9
Joined: Tue Aug 28, 2012 3:07 pm

Acquire on a separate thread

Post by EbenRoux » Mon Oct 01, 2012 11:46 am

Hello,

We will eventually be running our software on a central server that talks to multiple MFPs.

Is it possible to scan using Aquire on a separate thread? From what I can tell from another post along similar lines is that Aquire requires a UI thread?

Regards,
Eben

Alex
Site Admin
Posts: 1462
Joined: Thu Jul 10, 2008 2:21 pm

Re: Acquire on a separate thread

Post by Alex » Wed Oct 03, 2012 8:23 am

Hello Eben,

Yes, you can acquire image from scanner in a separate thread. Please see this topic: viewtopic.php?f=5&t=1560

Best regards, Alexander

EbenRoux
Posts: 9
Joined: Tue Aug 28, 2012 3:07 pm

Re: Acquire on a separate thread

Post by EbenRoux » Wed Oct 03, 2012 11:31 am

Hi Alex,

Yip, doing that already (AquireModal). Works OK.

My question actually relates to the 'Aquire' method (not AquireModal). Is it possible to run *that* on a separate thread?

Regards,
Eben

Alex
Site Admin
Posts: 1462
Joined: Thu Jul 10, 2008 2:21 pm

Re: Acquire on a separate thread

Post by Alex » Fri Oct 05, 2012 8:14 am

Hello Eben,
My question actually relates to the 'Aquire' method (not AquireModal). Is it possible to run *that* on a separate thread?
Acquire method also can be used when you acquire image(s) in the background thread. Do you have any problems?

Best regards, Alexander

EbenRoux
Posts: 9
Joined: Tue Aug 28, 2012 3:07 pm

Re: Acquire on a separate thread

Post by EbenRoux » Fri Oct 05, 2012 1:40 pm

Hi Alex,

I start a new thread (T2) from my main console thread (T1) and then create all the objects on T2 and call Aquire. But nothing happens after that. I let T1 spin since I need to wait for the scanning to complete but no scanning takes place.

Do you have a sample of this somewhere?

Regards,
Eben

EbenRoux
Posts: 9
Joined: Tue Aug 28, 2012 3:07 pm

Re: Acquire on a separate thread

Post by EbenRoux » Mon Oct 15, 2012 11:42 am

Any feedback yet?

Alex
Site Admin
Posts: 1462
Joined: Thu Jul 10, 2008 2:21 pm

Re: Acquire on a separate thread

Post by Alex » Thu Oct 18, 2012 4:37 pm

Hello Eben,

Sorry for a delay.

How your second thread waits while the image acquisition is finished?

Here is a snippet of correct code:

Code: Select all

[STAThread]
static void Main(string[] args)
{
    Thread thread1 = new Thread(AcquireImageFromDevice);
    thread1.Start();

    while (thread1.IsAlive)
    {
        Thread.Sleep(10);
    }
}

private void AcquireImageFromDevice()
{
    using (DeviceManager deviceManager = new DeviceManager())
    {
        deviceManager.Open();

        ...

        device.ImageAcquired += new EventHandler<ImageAcquiredEventArgs>(device_ImageAcquired);

        device.Acquire();

        while (device.State != DeviceState.Opened)
        {
            System.Windows.Forms.Application.DoEvents();
        }

        device.ImageAcquired -= new EventHandler<ImageAcquiredEventArgs>(device_ImageAcquired);
    }
}

private void device_ImageAcquired(object sender, ImageAcquiredEventArgs e)
{
    Console.WriteLine("Image is acquired");
}
Best regards, Alexander

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests