This project has moved and is read-only. For the latest updates, please go here.

Windows Service / Console application

Jul 18, 2015 at 5:58 AM
Hi, first : thanks for your work on that library.

I'd like to implement a windows service that exposes a web API to control a scanner.

I'm trying to figure out if Saraff.Twain.Net could be operated outside of a Windows Form application and I'm trying to test the library in a Console application without success.

Here is my barebone test code that fails in a console app :
       static void Main(string[] args)
        {
            Saraff.Twain.Twain32 _twain = new Twain32();

            _twain.IsTwain2Enable = true;
            _twain.ShowUI = false;


            _twain.OpenDSM();
            _twain.SourceIndex = 0;
            _twain.OpenDataSource();
            _twain.Acquire();
}
The problem is occurs in the OpenDataSource function. The error message is :
"Failure due to unknown causes."; ReturnCode = Failure; ConditionCode = Bummer
But the very same code in a windows forms button event handler works fine and the image is acquired.

Any idea of what the problem could be?

Thanks !

Vincent
Jul 18, 2015 at 6:06 AM
Ok, so by looking at Sample 3, I discovered that I needed to add [STAThread] :
 class Program
    {

        [STAThread]
        static void Main(string[] args)
        {
            Saraff.Twain.Twain32 _twain = new Twain32();
One thing that I wonder is if I can prevent the "Currently scanning" dialog. (ShowUI has no effect on that it seems) ? I'm not sure how this will react if I write a GUI-less windows service...

Thanks !
Jul 18, 2015 at 10:30 AM
Hello demvin.
Thanks you for your opinion about the Saraff.Twain.NET.
About implement a windows service: see Saraff.Twain.NET Remoting Samples, but it does not work in all cases because the TWAIN is targeted for work in desktop applications.
About the "Currently scanning" dialog: try use a CAP_INDICATORS, CAP_INDICATORSMODE, CAP_UICONTROLLABLE capabilities.
Marked as answer by SARAFF on 7/22/2015 at 9:58 AM
Jul 18, 2015 at 11:21 PM
Thanks a lot ! My windows service was crashing on Acquire() and setting CAP_INDICATORS to false _twain.Capabilities.Indicators.Set(false) fixed it !