Is there a way to execute a COM object method inside a completely new thread that is not tied to the main thread? I tried to use backgrounWorker and even use a new thread, running Dim thr as new Thread(AddressOf blah)and not working. I do not reference the COM object anywhere except the built-in "blah" function or the DoWork method for the background, but my main user interface is blocked when it tries to process the COM object methods that I call.
I really need to get this to execute methods from the com object in a separate thread, because it causes my application to completely block.
Below is an example of my thread that uses the DoWork method. The same logic can be used for the 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
, , . .
.