Scanning with BackgroundWorker

Discussions about TWAIN & WIA scanning in GdPicture.NET using GdPictureImaging.
baburajpb
Posts: 4
Joined: Thu Feb 04, 2010 2:02 pm

Scanning with BackgroundWorker

Post by baburajpb » Thu Feb 04, 2010 2:17 pm

I'm using following code to scan a document

Code: Select all

            GdPicture.GdPictureImaging gdPicture = new GdPicture.GdPictureImaging();
            gdPicture.SetLicenseNumber("XXXXXXXXXXXXXXXX");
            using (BackgroundWorker worker = new BackgroundWorker())
            {
                worker.DoWork += (s, ev) =>
                {
                    if (gdPicture.TwainOpenDefaultSource(IntPtr.Zero))
                    {
                        gdPicture.TwainSetHideUI(true);
                        int imgId = gdPicture.TwainAcquireToGdPictureImage(IntPtr.Zero);
                    }
                };
                worker.RunWorkerCompleted += (s, ev) =>
                {
                    gdPicture.TwainCloseSource();
                };
                worker.RunWorkerAsync();
            }
Though this code works for the first time, on subsequent calls to same code may not work. TwainAcquireToGdPictureImage(IntPtr.Zero) returns Zero. How to make GdPicture work with BackgroundWorker?

eagleman
Posts: 27
Joined: Mon Jan 25, 2010 1:48 pm

Re: Scanning with BackgroundWorker

Post by eagleman » Thu Feb 04, 2010 2:56 pm

Hi,

I have just submitted exactly the same problem but without the BackgroundWorker.

See: viewtopic.php?t=2299

eagleman

baburajpb
Posts: 4
Joined: Thu Feb 04, 2010 2:02 pm

Re: Scanning with BackgroundWorker

Post by baburajpb » Thu Feb 04, 2010 4:28 pm

I was going through the samples GdPicture has provided for its TWAIN APIs. None of them seems to have implemented any kind of threading. Most action just freezes the window.

User avatar
Loïc
Site Admin
Posts: 5701
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Scanning with BackgroundWorker

Post by Loïc » Thu Feb 04, 2010 5:37 pm

Hi there,

We are on this issue. See following link for quick fix: viewtopic.php?t=2299

Kind regards,

Loïc

eagleman
Posts: 27
Joined: Mon Jan 25, 2010 1:48 pm

Re: Scanning with BackgroundWorker

Post by eagleman » Thu Feb 04, 2010 5:42 pm

I read that there was some kind of threading problem. It is supposed to be fixed in the latest version, 6.6

eagleman

User avatar
Loïc
Site Admin
Posts: 5701
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Scanning with BackgroundWorker

Post by Loïc » Thu Feb 04, 2010 5:45 pm

Hi,
I read that there was some kind of threading problem.
It is not a threading issue at all. Please, try what I suggested this should work.

Kind regards,

Loïc

baburajpb
Posts: 4
Joined: Thu Feb 04, 2010 2:02 pm

Re: Scanning with BackgroundWorker

Post by baburajpb » Thu Feb 04, 2010 6:32 pm

Loïc wrote:Hi there,

We are on this issue. See following link for quick fix: viewtopic.php?t=2299

Kind regards,

Loïc

Hi using TwainUnloadSourceManager doesn't seems to be fixing the problem. You can try with BackgroundWorker code I pasted earlier.

User avatar
Loïc
Site Admin
Posts: 5701
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Scanning with BackgroundWorker

Post by Loïc » Thu Feb 04, 2010 6:34 pm

Hi,

I CAN'T help you more if you don't provide me the needed information. See link: viewtopic.php?t=1486

Kind regards,

Loïc

baburajpb
Posts: 4
Joined: Thu Feb 04, 2010 2:02 pm

Re: Scanning with BackgroundWorker

Post by baburajpb » Thu Feb 04, 2010 7:12 pm

Loïc wrote:Hi,

I CAN'T help you more if you don't provide me the needed information. See link: viewtopic.php?t=1486

Kind regards,

Loïc
Hi,

I'm using

GdPicture.NET - 6.6.0.1
Scanner model: HP ScanJet G2410
OS: Windows XP SP2
Code:

Code: Select all

 private void button1_Click(object sender, EventArgs e)
        {
            using (BackgroundWorker worker = new BackgroundWorker())
            {
                GdPicture.GdPictureImaging gdPicture = new GdPicture.GdPictureImaging();
                gdPicture.SetLicenseNumber("XXXXXXXX");

                worker.DoWork += (s, ev) =>
                {
                    if (gdPicture.TwainOpenDefaultSource(IntPtr.Zero))
                    {
                        gdPicture.TwainSetHideUI(true);
                        gdPicture.TwainSetIndicators(false);
                        int imgId = gdPicture.TwainAcquireToGdPictureImage(IntPtr.Zero);
                    }
                    gdPicture.TwainUnloadSourceManager(IntPtr.Zero);
                };
                worker.RunWorkerCompleted += (s, ev) =>
                {
                };
                worker.RunWorkerAsync();
            }
        }
Log file attached
log.zip
Log file
(1.06 KiB) Downloaded 124 times

User avatar
Loïc
Site Admin
Posts: 5701
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Scanning with BackgroundWorker

Post by Loïc » Thu Feb 04, 2010 7:24 pm

Hi,

You are using the WIA driver:

Code: Select all

Source: WIA-HP Scanjet G2410
Please, try with a real TWAIN driver.

With best regards,

Loïc

eagleman
Posts: 27
Joined: Mon Jan 25, 2010 1:48 pm

Re: Scanning with BackgroundWorker

Post by eagleman » Fri Feb 05, 2010 10:22 am

@baburajpb,

Loïc suggested to add a call to TwainSetAutoSourceClose(false) after opening the source.
That was the solution to my problem. Try it. Maybe it works for you too!

eagleman

anwarcode
Posts: 3
Joined: Fri Feb 05, 2010 5:31 pm

Scanning with BackgroundWorker Contd....

Post by anwarcode » Sat Feb 06, 2010 12:23 pm

Hi Loïc,

This is in continuation of the discussion Scanning with BackgroundWorker thread ….I have attached a log file, Log.txt, I have been using the TWAIN driver [HP Scanjet G2410 #2 TWAIN, please see the log] for the Twain Acquisition in the BackgroundWorker thread.

The application hangs for about 15-20 minutes when it executes [code: imageId = _gdPictureImaging.TwainAcquireToGdPictureImage(IntPtr.Zero); // Acquire image ] in the BackgroundWorker Thread. In fact, it initiates scanning and engages the scanner, the lamp tube does one complete cycle, but at the end no response it just get hanged and no image is acquired.
Note : We are using WPF as a host for GDPicture.

Code: Select all

                GdPicture.GdPictureImaging gdPicture = new GdPicture.GdPictureImaging();
                gdPicture.SetLicenseNumber("XXXXXXXXXXXXXXXX");
                using (BackgroundWorker worker = new BackgroundWorker())
                {
                    worker.DoWork += (s, ev) =>
                    {
                        if (gdPicture.TwainOpenDefaultSource(IntPtr.Zero))
                        {
                            gdPicture.TwainSetHideUI(true);
                            int imgId = gdPicture.TwainAcquireToGdPictureImage(IntPtr.Zero);
                        }
                    };
                    worker.RunWorkerCompleted += (s, ev) =>
                    {
                        gdPicture.TwainCloseSource();
                    };
                    worker.RunWorkerAsync();
                }
Please find the solution and update as soon as possible, for your reference I have added the code and attached the Log file, Log.txt.

Regards,
Anwar

User avatar
Loïc
Site Admin
Posts: 5701
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Scanning with BackgroundWorker

Post by Loïc » Sat Feb 06, 2010 1:08 pm

Hi,

There is no attached LOG.

Kind regards,

Loïc

anwarcode
Posts: 3
Joined: Fri Feb 05, 2010 5:31 pm

Re: Scanning with BackgroundWorker

Post by anwarcode » Sat Feb 06, 2010 1:56 pm

Hi,
log.7z
(578 Bytes) Downloaded 130 times
Please find the attached log file Log.txt

Best Regards
Anwar

User avatar
Loïc
Site Admin
Posts: 5701
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Scanning with BackgroundWorker

Post by Loïc » Sat Feb 06, 2010 2:00 pm

Hi,

OK, the problem come form an unreceived message from the scanner to your application. This can be caused by a timer, a hook or an unstable scanner driver.

To be able to investigate on your issue we need a basic application which reproduces the problem. Please, send this app. to essuport (at) gdpicture (dot) com.

With best regards,

Loïc

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests