Can someone please help with this as I have scoured the net for hours trying to find a solution to this.
I have a multi-threaded app (it needs to be that way) and I am trying to update a text message box on the main form from a MODULE. I have code that will work if I update from the main form itself but I need to update the form from a MODULE.
Here is what I have.
Delegate Sub Update_MessagesDelegate(ByVal sMessage As String)
Sub Update_Messages(ByVal sMessage As String)
Try
If frmMain.InvokeRequired Then
Dim oDelegate As New Update_MessagesDelegate(AddressOf Update_Messages)
Dim f As frmMain = My.Application.OpenForms("frmMain")
f.Invoke(oDelegate, New Object() {sMessage})
Else
frmMain.txtMessages.Text = String.Concat(Now.ToString + " - " + sMessage.Trim, System.Environment.NewLine, frmMain.txtMessages.Text)
Msgbox("Frmmain Should Say " + frmMain.txtMessages.Text)
End If
Catch ex As Exception
msgbox("Error In Update_Messages : " + ex.message)
End Try
End Sub
Now, if I run the code my first msgbox tells me CORRECTLY what should be displayed each time but my form never updates!
This is maddening!
Can anyone help?
I have a multi-threaded app (it needs to be that way) and I am trying to update a text message box on the main form from a MODULE. I have code that will work if I update from the main form itself but I need to update the form from a MODULE.
Here is what I have.
Delegate Sub Update_MessagesDelegate(ByVal sMessage As String)
Sub Update_Messages(ByVal sMessage As String)
Try
If frmMain.InvokeRequired Then
Dim oDelegate As New Update_MessagesDelegate(AddressOf Update_Messages)
Dim f As frmMain = My.Application.OpenForms("frmMain")
f.Invoke(oDelegate, New Object() {sMessage})
Else
frmMain.txtMessages.Text = String.Concat(Now.ToString + " - " + sMessage.Trim, System.Environment.NewLine, frmMain.txtMessages.Text)
Msgbox("Frmmain Should Say " + frmMain.txtMessages.Text)
End If
Catch ex As Exception
msgbox("Error In Update_Messages : " + ex.message)
End Try
End Sub
Now, if I run the code my first msgbox tells me CORRECTLY what should be displayed each time but my form never updates!
This is maddening!
Can anyone help?