JumpyNET
Centurion
- Joined
- Apr 4, 2005
- Messages
- 196
I want to catch events in my main form and change the title to match the input from the event. I'm getting errors about crossthreading. Can some one please help me get this small test program working?
Here is the whole code:
Here is the whole code:
Code:
Public Class Form1
Private WithEvents Worker As New WorkerClass
Private Sub Worker_ProgressChanged(ByVal Progress As Integer) Handles Worker.ProgressChanged
Me.Text = Progress
End Sub
End Class
Code:
Public Class WorkerClass
Public Event ProgressChanged(ByVal Progress As Integer)
Private t As Threading.Thread
Public Sub New()
t = New Threading.Thread(AddressOf MainThread)
t.Name = "BackgroundThread"
t.IsBackground = True
t.Start()
End Sub
Private Sub MainThread()
Dim Progress As Integer = 0
Do Until Progress = 10
Threading.Thread.Sleep(1000)
Progress += 1
RaiseEvent ProgressChanged(Progress)
Loop
End Sub
End Class