I'm just learning threading in VB and I'm having trouble using a delegate to sent information back to the main form. This is what I have;
The Main Form
The Class Object to be the Thread
When I run this test code, I get the messageboxes indicating the thread is running, the event is raised and caught, but the call back to the text box on the main form is not working. Can anyone point me in the right direction here?
Thanks,
Bernie
The Main Form
VB.NET:
Dim myThreadObject As ThreadObject
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myThreadObject = New ThreadObject
AddHandler myThreadObject.ThreadFinished, AddressOf ThreadFinishedEventHandler
End Sub
Private Sub RunTheThread()
Dim myThread As Threading.Thread
' run the thread ...
myThread = New Threading.Thread(AddressOf myThreadObject.main)
myThread.Start()
End Sub
Public Sub UpdateTextBox(ByVal message As String)
tbOutput.Text = message
End Sub
Sub ThreadFinishedEventHandler()
MessageBox.Show("Thread completed")
End Sub
The Class Object to be the Thread
VB.NET:
Public Class ThreadObject
Public Event ThreadFinished()
Dim myUpdateTextBox As dlgUpdateTestBox
Public Delegate Sub dlgUpdateTestBox(ByVal Message As String)
Public Sub New()
myUpdateTextBox = New dlgUpdateTestBox(AddressOf Form1.UpdateTextBox)
End Sub
Public Sub main()
MessageBox.Show("Thread running")
myUpdateTextBox("Thread is finished")
RaiseEvent ThreadFinished()
End Sub
End Class
When I run this test code, I get the messageboxes indicating the thread is running, the event is raised and caught, but the call back to the text box on the main form is not working. Can anyone point me in the right direction here?
Thanks,
Bernie