Example 5
Creating a Thread object in VB.NET
1: Private Delegate Sub AddInvoker(ByVal Elem As String) 2: Private Sub AddElem(ByVal Elem As String) 3: ListBox1.Items.Add(Elem) 4: End Sub 5: 6: Private Sub ThreadStartProcedure() 7: Dim I As Integer 8: Try 9: For I = 0 To 100000 10: If (Me.InvokeRequired) Then 11: Me.Invoke(New AddInvoker(AddressOf AddElem), _ 12: New Object() {I.ToString()}) 13: End If 14: Next 15: Catch 16: Thread.CurrentThread.Join() 17: End Try 18: End Sub 19: 20: Private Sub Form1_Load(ByVal sender As System.Object, _ 21: ByVal e As System.EventArgs) Handles MyBase.Load 22: AddHandler Application.Idle, AddressOf OnIdle 23: 24: ' 3: Demonstrates using a thread object 25: Dim Thread As New Thread( _ 26: AddressOf ThreadStartProcedure) 27: Thread.IsBackground = True 28: Thread.Start() 29: 30: Splash.Splash() 31: 32: End Sub 33: 34: End Class