saraff-9EB1047A4BEB4cef8506B29BA325BD5A / Saraff.Twain.NET

Saraff.Twain.NET is the skillful scanning component which allows you to control work of flatbed scanner, web and digital camera and any other TWAIN device from .NET environment. You can use this library in your programs written in any programming languages compatible with .NET technology.
GNU General Public License v3.0
102 stars 35 forks source link

Check if device is connected before opening DataSource #21

Closed MrBlueHere closed 6 years ago

MrBlueHere commented 6 years ago

Hi,

I ran into a little issue. I have a code set up, where I loop through twain.SourcesCount and retrieve info about sources, like id, name, manufacturer, etc. Problem arises when I call to twain.OpenDataSource(), which causes my app to freeze for some time. What happens is, that scanner driver will open window with info saying, that device is disconnected (this takes 10 seconds or more). Exception (DG DAT MSG out of expected sequence) is thrown only after the window is closed by the user. My app is being used like back-end webservice, so it‘s uncomfotable for front-end to wait for my app when it gets to this „waiting for drivers ui state“.

Also I know, that simply connecting scanner will solve the issue, I'm just trying to prevent this, so my app doesn't hang for such a long time.

Is there a way to check if a specific device is connected before opening DataSource? Or somehow block this driver ui?

By the way, I always set Twain.Ui to false, so this doesn't help to block driver ui.

Thank you.

saraff-9EB1047A4BEB4cef8506B29BA325BD5A commented 6 years ago

Hello, @MrBlueHere Unfortunately, impossible to check if a specific device is connected before opening DataSource. But you can use background thread for opening a DS in external process. See the Saraff.Twain.OutprocSample4 in the Saraff.Twain.NET Outproc Samples.

MrBlueHere commented 6 years ago

Thank you, outproc may help.