Is there any way to execute a method of a com object inside a completely new thread, not attached to the main thread? I have tried using a backgrounWorker, and even using a new thread by doing Dim thr as new Thread(AddressOf blah)
and neither work. I am not referencing the COM object anywhere but inside the threaded function "blah" or the backgroundWorker's DoWork method, yet still my main UI locks up as it tries to process the COM object's methods I am calling.
I really need to make this execute the methods from the com object in a separate thread because it is causing my whole application to lock up.
Below is an example of my Thread that uses a method "DoWork". The same logic can be taken for a background worker
Public Sub Reconnect_Scanner() Implements Scanners.Reconnect_Scanner
'Do our request on a new thread
Dim thread As New System.Threading.Thread(AddressOf Connect)
thread.SetApartmentState(Threading.ApartmentState.STA)
thread.Start()
End Sub
Public Sub Connect()
'Get a new instance of our scanner
Dim scanner As New OposScanner_CCO.OPOSScanner
'Loop until scanner is opened
Do
Debug.Print("looking for scanner")
'If we find the device, exit do
Dim openId As Integer = scanner.Open("Honeywell")
If openId = 0 Then Exit Do
'Sleep 1 second
System.Threading.Thread.Sleep(250)
Loop
End Sub
Even though that should be running on a completely new thread, once it does scanner.open my main thread locks up till it is complete.
I appreciate any help.