Closed MrBlueHere closed 6 years ago
Hello, @MrBlueHere I has changed code of a Saraff.Twain.Aux (you can see that in a commit). Now you can write follow:
IDisposable _host = null;
TwainExternalProcess.Execute (
"path_of_host_file",
(twain, host) => {
_host = host;
// ...
})
Wow, thanks. I'll try it out.
I was trying to test it out, but I found that I'm using older version of Saraff.Twain -> 1.0.22.544. After updating to 1.0.27.606, behavior changed when doing outproc operations. It doesn't matter which version of Saraff.Twain.Aux I use, the issue is still there. I can start TwainExternalProcess, but when calling twain.SourcesCount, this error comes up:
[5] Message: System.InvalidOperationException: Operation is not valid due to the current state of the object.
Server stack trace: at Saraff.Twain.Aux.TwainExternalProcess.AuxProcess.Execute(TwainCommand command) at Saraff.Twain.Aux.Twain32RealProxy.Invoke(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Saraff.Twain.Twain32.get_SourcesCount()
at ScanApp.Models.Scanner.<>cDisplayClass60_0.2 execCallback) at Saraff.Twain.Aux.TwainExternalProcess.Execute(String fileName, Action
1 execCallback)
at ScanApp.Models.Scanner.GetTwainScanners() in D:\Projects\ScanApp\ScanApp\ScanApp\Models\Scanner.cs:line 116
I'm not sure what's wrong, I looked at Saraff.Twain.NET Service Samples (UPDATED at 05.05.2017) and the way TwainExternalProcess is started is the same as my. Also I see that processes are created just fine but crash right away.
Edit: As this probably isn't related to this issue, I can create a new one if you want.
In projects of external processes you similarly has updated version of Saraff.Twain ?
I forgot to update it, that was the problem, thanks. I've also tested out closing/disposing external process and it works as expected.
Thank you very much.
Ok. I has published a Saraff.Twain.Aux 1.0.3.632 nuget package.
Hi,
to explain my situation: I'm wrapping TwainExternalProcess.Execute method inside Task.Run and I do twain.OpenDataSource in newly created process. This way my app doesn't lock if device isn't online and when device driver displays it's own message/s on the screen and blocks the program flow. I wrap it inside task, so that I can wait certain timeout period for it to complete and if it doesn't, I throw a TimeoutException signaling that device wasn't connected in timely fashion and is probably offline. This has proven to me as a fairly good way to check if device is online.
My problem is that after creating these processes and doing twain.OpenDataSource, the driver UI messages stay on the screen waiting to be closed by the user. This behavior isn't wanted.
A possible solution I see is to close those TwainExternalProcesses I created and thereby also closing driver-generated messages. How could I do that? I see, that in AuxProcess is a method End(), which is what I need, but it's not accessible from outside.
I know that I could look for these processes with System.Management, but I didn't really want to do this, as I don't know how to identify each specific TwainExternalProcess (in case there are more devices offline).
Thank you and have a nice day.