I have a background thread like:
Public Class Main
Private Sub StartBackgroundThread()
Dim threadStart As New Threading.ThreadStart(AddressOf DoStuffThread)
Dim thread As New Threading.Thread(threadStart)
thread.IsBackground = True
thread.Name = "Background DoStuff Thread"
thread.Start()
End Sub
Private Sub DoStuffThread()
Do
Do things here .....
If something happens Then
ExitProgram(message)
End If
Loop
End Sub
Private Sub ExitProgram(ByVal message As String = "")
MessageBox.Show(message)
Application.Exit()
End Sub
End Class
The thread keeps running to check some conditions, and once the condition is met, I want to call the ExitProgram to exit the whole application. The problem is the message box pops up without freezing the main thread (UI) resulting in the user can still operate on the UI which is not allowed.
I wonder how to call the ExitProgram method as it is called from Main thread so that the UI cannot be operated until the message box is dismissed ?