Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- BackgroundWorker1.RunWorkerAsync()
- End Sub
- Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
- For i As Integer = 2 To 9
- Timer1.Enabled = True
- SetLabelText_ThreadSafe(Label1, "2 * " & (i))
- Threading.Thread.Sleep(500)
- Next
- End Sub
- ' The delegate
- Delegate Sub SetLabelText_Delegate(ByVal [Label] As Label, ByVal [text] As String)
- ' The delegates subroutine.
- Private Sub SetLabelText_ThreadSafe(ByVal [Label] As Label, ByVal [text] As String)
- ' InvokeRequired required compares the thread ID of the calling thread to the thread ID of the creating thread.
- ' If these threads are different, it returns true.
- If [Label].InvokeRequired Then
- Dim MyDelegate As New SetLabelText_Delegate(AddressOf SetLabelText_ThreadSafe)
- Me.Invoke(MyDelegate, New Object() {[Label], [text]})
- Else
- [Label].Text = [text]
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement