I was stuck on this for hours where the event raised from the class wouldn' t write to my textbox in the presentation layer.
I googled but could not find any concrete solution to this but at last after going through various websites i figured out the easier way to solve this.
This article will help users to call the function in the class and raise an event within the class and catch the event in form and display whatever message raised to the text boxes in multi threaded application (VB.net)
Lets go step by step now:
1. I have a form with command button cmdTest and text box txtAction where I display my messages raised from the class.
Dim robot As New RobotProcess_Ama(Nothing)
AddHandler robot.TaskProcessed, AddressOf ActionLog
WorkerThread = New Threading.Thread(AddressOf robot.CheckQueue)
WorkerThread.Start()
End Sub
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
txtAction.Text = TimeString & "From: " & FunctName & ":" & aMessage
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = True
End Sub
Here i disabled checkforIllegalcrossThreadcalls and re-enabled them after finishing.
2. Now my class RobotProcess_Ama contains function called checkqueue and raises the message.
Public Sub CheckQueue()
TryRaiseEvent TaskProcessed("From Class", TimeString & ": Creating log file")
' Threading.Thread.Sleep(200)
Catch ex As Exception
Throw ex
End Try
End Sub
Read more!