' Collection of code snippets by Arne Vajhøj ' posted to eksperten.dk, usenet and other places (2002-now) Imports System Imports System.Threading Public Class Form1 Private done As Boolean Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click done = False Dim t As Thread = New Thread(AddressOf TextUpdateThread) t.Start() End Sub Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click done = True End Sub Private Sub TextUpdateThread() Dim i As Integer = 0 While Not done i = i + 1 If TextBox1.InvokeRequired Then TextBox1.Invoke(New TextUpdateHandler(AddressOf TextUpdate), New Object() {i}) Else TextUpdate(i) End If Thread.Sleep(1000) End While End Sub Private Delegate Sub TextUpdateHandler(ByVal n As Integer) Private Sub TextUpdate(ByVal n As Integer) TextBox1.Text = n.ToString() End Sub End Class