Private Sub Count()
Dim i As Integer = 0
Do While True
i += 1
ListBox1.Items.Add(i)
Loop
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Count()
End Sub
Sub SomeLongRunningCode()
Dim Counter As Long = 1
While Counter <= 100000000000000
ListBox1.Items.Add(Counter)
Counter += 1
End While
End Sub
Dim WorkerThread As New Threading.Thread(AddressOf SomeLongRunningCode) WorkerThread.Start()
Delegate Sub AddItem(ByVal Item As Long)
Sub AddToList(ByVal Item As Long)
If ListBox1.InvokeRequired Then
ListBox1.Invoke(New AddItem(AddressOf AddToList), Item)
Else
ListBox1.Items.Add(Item)
End If
End Sub
ListBox1.Items.Add(Item)
Sub SomeLongRunningCode()
Dim Counter As Long = 1
While Counter <= 100000000000000
AddToList(Counter)
Counter += 1
End While
End Sub
Dim WorkerThread As New Threading.Thread(AddressOf SomeLongRunningCode) WorkerThread.Start()