views:

89

answers:

0

I've written an applet to allow scanning. This applet uses the TWAIN standard. This standard is used to communicate with scanners. I know TWAIN requires access to UI threads in Windows. The code I wrote worked well when it was used in an applet. The problem starts when I try to use the same code in an console application. I suspect this may have something to do with the access to UI threads.

I'm wondering if it is possible to access UI threads when launching console application written in Java. I think in C# it is possible since any console application can for example show MessageBox. In the case of Java I'm not sure about it.

As requested below is the stacktrace. Scanning library is JTwain and I'm launching the Java code remotely. The web application, which is a frontend for the user, is written in Perl and uses the Java module. It works like a remote procedure call. There's a JavaServer instance which handles calls from Perl scripts. JavaServer then call the aforementioned scanning with JTwain. The UI threads problem is my first guess since as I wrote above the scanning code works well under an applet.

Failed to acquire image

com.asprise.util.jtwain.JTwainException: Failed to acquire image
    at com.asprise.util.jtwain.Source.acquireImage(Source.java:230)
    at com.XXX.XXX.scanning.ScanningWorker.scan(ScanningWorker.java:57)
    at com.XXX.XXX.scanning.ScanningServer.scan(ScanningServer.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.zzo.javaserver.Dealer.callFunction(Dealer.java:867)
    at com.zzo.javaserver.Dealer.parse(Dealer.java:541)
    at com.zzo.javaserver.Dealer.run(Dealer.java:431)
com.asprise.util.jtwain.JTwainException: Failed to unload source manager.   at     com.asprise.util.jtwain.lowlevel.Control.unloadSourceManager(Control.java:94)
    at com.asprise.util.jtwain.SourceManager.closeSourceManager(SourceManager.java:120)
    at com.XXX.XXX.scanning.ScanningWorker.scan(ScanningWorker.java:84)
    at com.XXX.XXX.scanning.ScanningServer.scan(ScanningServer.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.zzo.javaserver.Dealer.callFunction(Dealer.java:867)
    at com.zzo.javaserver.Dealer.parse(Dealer.java:541)
    at com.zzo.javaserver.Dealer.run(Dealer.java:431)