I am evaluating the gdpicture.net. I came across this issue, I whould appreciate help.
I scan on a program that is need to be reset to its starting point after a certain time that there was no activity on the form. (It's a kiosk app so if a user left in middle of a session, we need to programmatically cancel out the unfinished work, so the next user can start from begging).
Now I call the TwainAcquireToGdPictureImage, it all work great but I try to have a timer that calls TwainCloseSource if let's say 60 secunds pessed by and the user have not scanned (the code waits for the return of TwainAcquireToGdPictureImag), when the closecource is called my program crashes if the twain is still waiting, (simply creshing, I cannot handle the error with try catch, as the bug is in the gdpicture.net clr).
I can call closecource only when the TwainAcquireToGdPictureImage is finish, but not when it's still running.
I use vfp and gdpicture as com, I can confirm that the gdpicture.net is crashing as I don't get any errors in vfp, I just see the .net clr.dll crash in event viewer.
I need a way of cancelling an initiated twain acquire without user input.
This is also important for other reason, as I hide the scanner ui, sometimes the ui just waits for user input and the user has not way of doing it as its hidden. But if I whould be able to cancel out the scan with a timer then this whould be solved as well for my needs.
Calling twaindisablesource did work. For me, but still crashes when call afterwards closecource
It cannot be done that easily, disabling source or simply closing it in the middle of an ongoing transfert will most probably crash and you absolutely need to know the TWAIN source state before doing anything in order to do what's right at the moment (and not only in this context, it should be the golden rule in any TWAIN application).
To know the TWAIN source state you need to use the TwainGetState method, it will return an TwainStatus enumeration member as listed here.
Now, depending on the TWAIN state there are different options:
If the state is 4 (TWAIN_SOURCE_OPEN) or 5 (TWAIN_SOURCE_ENABLED) then you may just close it without issue with the TwainCloseSource method as there is no action pending.
However if the TWAIN state is 7 (TWAIN_TRANSFERRING) or 6 (TWAIN_TRANSFER_READY), then you need to cancel the transfer first and when done, after checking the state again, you may close the source.
The TwainEndAllXfers method is probably what you need in that case as it will stop all the transfers and will return to TWAIN_SOURCE_ENABLED, please see here.
I hope this helps.
Who is online
Users browsing this forum: Majestic-12 [Bot] and 0 guests