home *** CD-ROM | disk | FTP | other *** search
- Public Class Form1
- Inherits System.Windows.Forms.Form
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- 'Add any initialization after the InitializeComponent() call
-
- End Sub
-
- 'Form overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
- Friend WithEvents Panel1 As System.Windows.Forms.Panel
- Friend WithEvents btnPause As System.Windows.Forms.Button
- Friend WithEvents btnStop As System.Windows.Forms.Button
-
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.Container
-
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Me.btnPause = New System.Windows.Forms.Button()
- Me.btnStop = New System.Windows.Forms.Button()
- Me.ListBox1 = New System.Windows.Forms.ListBox()
- Me.Panel1 = New System.Windows.Forms.Panel()
- Me.Panel1.SuspendLayout()
- Me.SuspendLayout()
- '
- 'btnPause
- '
- Me.btnPause.Location = New System.Drawing.Point(0, 8)
- Me.btnPause.Name = "btnPause"
- Me.btnPause.Size = New System.Drawing.Size(72, 24)
- Me.btnPause.TabIndex = 0
- Me.btnPause.Text = "Pause"
- '
- 'btnStop
- '
- Me.btnStop.Location = New System.Drawing.Point(72, 8)
- Me.btnStop.Name = "btnStop"
- Me.btnStop.Size = New System.Drawing.Size(72, 24)
- Me.btnStop.TabIndex = 1
- Me.btnStop.Text = "Stop"
- '
- 'ListBox1
- '
- Me.ListBox1.Dock = System.Windows.Forms.DockStyle.Fill
- Me.ListBox1.IntegralHeight = False
- Me.ListBox1.Location = New System.Drawing.Point(5, 5)
- Me.ListBox1.Name = "ListBox1"
- Me.ListBox1.Size = New System.Drawing.Size(282, 231)
- Me.ListBox1.TabIndex = 0
- '
- 'Panel1
- '
- Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnStop, Me.btnPause})
- Me.Panel1.Dock = System.Windows.Forms.DockStyle.Bottom
- Me.Panel1.Location = New System.Drawing.Point(5, 236)
- Me.Panel1.Name = "Panel1"
- Me.Panel1.Size = New System.Drawing.Size(282, 32)
- Me.Panel1.TabIndex = 1
- '
- 'Form1
- '
- Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
- Me.ClientSize = New System.Drawing.Size(292, 273)
- Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ListBox1, Me.Panel1})
- Me.DockPadding.All = 5
- Me.Name = "Form1"
- Me.Text = "Form1"
- Me.Panel1.ResumeLayout(False)
- Me.ResumeLayout(False)
-
- End Sub
-
- #End Region
-
- Sub RunThread()
- Do
- SyncLock (ListBox1)
- ListBox1.Items.Add("The thread is executing")
- End SyncLock
- Threading.Thread.CurrentThread.Sleep(1000)
- Loop
- End Sub
-
- Private newThread As New Threading.Thread(AddressOf RunThread)
-
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- newThread.Start()
- End Sub
-
- Private Sub btnPause_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPause.Click
- If btnPause.Text = "Pause" Then
- newThread.Suspend()
- btnPause.Text = "Resume"
- Else
- newThread.Resume()
- btnPause.Text = "Pause"
- End If
- End Sub
-
- Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
- newThread.Abort()
- newThread.Join()
- MsgBox("Thread terminated")
- End Sub
-
- End Class
-