This project has moved. For the latest updates, please go here.

Does not work in Timer events

May 1, 2014 at 5:51 AM
My program is to get scan command from a table. So I create the Saraff TWAIN object in a timer event, it can work well in WIN7, but it does not work in Win XP.
Physical scanner can start after there is a command come, but once scan finished, the program will hange, I try to catch the exception in the AcquireCompleted event, but no response.
Can you give me any hint what's wrong? thx.
Coordinator
May 1, 2014 at 6:59 PM
Hello, xgc521.
I think that the error in your program. For example, the Saraff.Twain.Twain32 object must be created when the program starts, when the timer fires, then invoked the Acquire method.
May 2, 2014 at 1:30 AM
Hi Saraff,

please see the sample code like below, in fact I create Saraff.Twain.Twain32 object if it is null when the timer fires, it can work well in Win7 but does not work in WinXP.

private void timerScan_Tick(object sender, EventArgs e)
{
    if (twain321 ==null)
       twain321 = new Saraff.Twain.Twain32();

        twain321.ShowUI = false;
        twain321.AcquireCompleted += twain321_AcquireCompleted;

      twain321.OpenDSM();
      twain321.SourceIndex =0;
      twain321.OpenDataSource();

     twain321.Acquire();
}
Coordinator
May 2, 2014 at 5:59 AM
Edited May 2, 2014 at 10:17 AM
Hello, xgc521.
I think that there are not enough pairs of parentheses.
private void timerScan_Tick(object sender, EventArgs e) {
    try {
        if(this._twain32==null) {
            this._twain32=new Saraff.Twain.Twain32();
            this._twain32.ShowUI=false;
            this._twain32.AcquireCompleted+=twain321_AcquireCompleted;

           this._twain32.OpenDSM();
           //_twain32.SourceIndex=0; // this superfluous
           this._twain32.OpenDataSource();
        }
        this._twain32.Acquire();
    } catch(Exception ex) {
        // <<< exception handler
    }
}
Marked as answer by SARAFF on 6/23/2014 at 12:30 PM
May 2, 2014 at 7:34 AM
Hi Saraff,

Thanks for your kind support, do you know anyone running previous code successfully in WinXP? I did not have a scanner now , so cannot validate it immediately.

Btw, if comment the SourceIndex setting code, it will use the default scanner (index is 0) ,correct?
Coordinator
May 2, 2014 at 10:15 AM
Edited May 2, 2014 at 10:30 AM
Hello, xgc521.
Saraff.Twain.NET was tested for Windows 2000 / XP / 2003 / Vista / 2008 / 7, 32-bit / 64-bit.
See Minimal implementation and Alternative User Interfaces