File: WinThreadDemo.VB.Txt Date: 7/29/04 By: Dan Garlen, MCT MCT04@Garlen.Net --------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------- WinThreadDemo Controls: btnNewThread lstDisplay btnSelfDestruct btnCount --------------------------------------------------------------------------------------- Private Sub btnNewThread_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewThread.Click NewThread() End Sub Private Sub NewThread() lstDisplay.Items.Insert(0, "Starting New Thread") Dim t As Thread = New Thread(AddressOf Count) threadCount += 1 t.Name = "Thread " & threadCount.ToString t.IsBackground = True t.Start() End Sub Sub Count() Dim i As Integer For i = 1 To 10 Dim str As String = Now.ToLongTimeString & ": " & Thread.CurrentThread.Name & ": " & i.ToString lstDisplay.Items.Insert(0, str) Me.Refresh() Thread.CurrentThread.Sleep(1000) Next End Sub Private Sub btnSelfDestruct_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelfDestruct.Click Dim i As Integer For i = 1 To 10000 NewThread() Next End Sub Private Sub btnCount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCount.Click lstDisplay.Items.Insert(0, "Starting Sync Count") Me.Update() Count() lstDisplay.Items.Insert(0, "End Sync Count") End Sub