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 »

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: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Acquire on a separate thread

Post by Alex »

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 »

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: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Acquire on a separate thread

Post by Alex »

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 »

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 »

Any feedback yet?
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Acquire on a separate thread

Post by Alex »

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