Link to home
Start Free TrialLog in
Avatar of UiTroi
UiTroi

asked on

Multi-threading

I tried to write an windows application using my .dll file.  I created a library MyLibrary in which I implemented a class called Scanner.  In the Scanner class, I had a method called Scanning which used a method from another .dll file to scan the driver license.  In the Scanner class, I also had another method called MyThread which created a thread with the starting entry is Scanner (New Thread(AddressOf Me.Scanner)).  Also, I created a windows application with a form and a button.  I import MyLibrary into this windows application.  When I click the button on the form to scan the driver license, the scanner scanned the driver license, but I could not interact with the form to type something in during the time the scanner scanned the driver license.  After it finished scanning, then I could interact with the form.  Is there anyway that I can interact with the form during the time the scanner scans the driver license? Please help me out and it would be nice if I can see the sample code.  Thanks.
Avatar of KeirGordon
KeirGordon

It is hard to help without seeing some of your code, but typically to solve an issue such as this one would insert Application.DoEvents() calls within any loops they have.  This call allows any pending messages to be proccessed and thus will often fix the issue of your form not responding while in a loop.

ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oops forgot when the thread dies to set it to nothing (so isRunning still works ...)

also I believe its Stop() on the thread not abort()

http://www.dotnetbips.com/displayarticle.aspx?id=39 is a decent itro to threading reference
Also MSDN has a ton of good examples if you look in the threading area :)
Avatar of UiTroi

ASKER

This is not quite what I need, but it gives me the direction.  The problem was that when I was scanning, all theads were blocked.  I think that it is the problem of ActiveX control.  Anyway, thanks a lot for your time and your help.
the code above handles that case by starting a thread (which gets blocked) and calling back to your other thread (which is still alive) when the image completed scanning ...

this creates a thread and returns to your main thread.
    Public Sub Scanning()
          //lock this
          SingleScanThread=new Thread
          (new ThreadStart(addressof Me.GetMyImage))
          //unlock this
    End Sub

this runs in the new thread
    Protected Sub GetMyImage()
          try
              //this calls your activex control
              dim img as Image = OtherLibrary.DoScan()

              //this messages your first thread which has been processing other tasks that the image has been completed (and delivers the image to the first thread)
              OnScanCompleted(img)
          catch Ex as ThreadException
              'Thread was cancelled
          catch Ex as Exception
              'Raise most likely another event which would alert the user to the other error
          end try
    End Sub