Basically it's this question but then for VB.net. I need to check the CheckBox
state from another thread than the main thread. Solutions for the linked question contain C# code. On-line translators do not yield understandable results.
My code (stripped down to the essential parts):
Public Class UI
'UI contains CheckBox1.
End Class
Public Class Worker
Public Sub Input()
Dim thrMyThread As New System.Threading.Thread(AddressOf Run)
thrMyThread.Start()
End Sub
Public Sub Run()
If UI.CheckBox1.Checked = True
MsgBox("True")
ShellandWait("application.exe")
Else
MsgBox("False")
ShellandWait("application.exe")
End If
End Sub
End Class
ShellandWait
is a custom function which starts a process and waits until it exits.
Because of the ShellandWait
I need another thread to keep my UI responsive.
UPDATE
I did find a work around by defining a Public
boolean variable at the beginning of the Worker Class, which represents the state of the UI.CheckBox
. So:
Public Class Worker
Public cB As Boolean = UI.CheckBox.Checked
... 'Rest of Code
Public Sub Run()
If cB = True
MsgBox("True")
ShellandWait("application.exe")
Else
MsgBox("False")
ShellandWait("application.exe")
End If
End Sub
End Class