ibigpapa
New member
- Joined
- Jan 4, 2008
- Messages
- 4
- Programming Experience
- 1-3
So I'm trying to update a text box, I start a thread with the thread.start() method, The thread runs a class method. I have it raise an event at a certain location with a string of information, in the main form I handle the event, it takes the string and adds to a text box. I get error stating this is not thread safe, I've looked at the background worker, but I am still unable to see how to apply it to my code.
So if someone could show me how to turn this into a backgroundworker or how to make this thread safe that would be great. Thank you in advance
the code to create thread in the main form
Code of the class
So if someone could show me how to turn this into a backgroundworker or how to make this thread safe that would be great. Thank you in advance
the code to create thread in the main form
VB.NET:
Public Class form1
Dim WithEvents oClass as testClass
Dim oThread as Thread
Sub button1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
oClass = New testClass()
oThread = New Thread(AddressOf oClass.start)
oThread.Start()
end sub
Public Sub oClassResultEvent(ByVal strResult As String) Handles oClass.classResult
textbox1.Text &= strResult & ControlChars.NewLine
End Sub
End Class
Code of the class
VB.NET:
Public Class testClass
Public Sub start()
For I as Integer = 1 to 100
RaiseEvent classResult(i)
Next
End Sub
Public Event classResult(ByVal strResult as String)
End Class
Last edited: