این تکه برنامه مثالی
برای Multi Threading از خودم است.
یک پروژهی Visual Basic.Net Windows Application
درست کنید و تکه کد زیر را در کد فرم آن Paste کنید.
Private tDraw As New
System.Threading.Thread(AddressOf DrawArc)
Private tIncSt As New
System.Threading.Thread(AddressOf IncStart)
Private tIncSw As New
System.Threading.Thread(AddressOf IncSweep)
Private tDecSw As New
System.Threading.Thread(AddressOf DecSweep)
Private bm As New
Bitmap(450, 450, Imaging.PixelFormat.Format24bppRgb)
Private gr As Graphics =
Graphics.FromImage(bm)
Private arsT, arsW As Integer
Private dPen As Pen
Private Sub frmMain_Load(ByVal
sender As System.Object,
ByVal e As System.EventArgs)
Handles MyBase.Load
Me.ClientSize =
New Size(450, 450)
dPen = New
Pen(Color.CornflowerBlue, 10)
arsT = 0
arsW = 180
tDraw.IsBackground =
True
tDraw.Name =
"tDraw"
tDraw.Start()
tIncSt.IsBackground =
True
tIncSt.Name =
"tIncSt"
tIncSt.Start()
tIncSw.IsBackground =
True
tIncSw.Name =
"tIncsW"
'tIncSw.Priority
= 1
tIncSw.Start()
tDecSw.IsBackground = True
tDecSw.Name =
"tDecsW"
'tDecSw.Priority
= 3
tDecSw.Start()
End Sub
Private Sub DrawArc()
While True
gr.Clear(Color.White)
Dim graph
As Graphics = Me.CreateGraphics()
Dim r
As New Rectangle(50, 50, 350, 350)
gr.DrawArc(dPen, r, arsT, arsW)
graph.DrawImage(bm, 0, 0)
System.Threading.Thread.Sleep(10)
End While
End Sub
Private Sub IncStart()
While True
arsT += 1
System.Threading.Thread.Sleep(20)
End While
End Sub
Private Sub IncSweep()
While True
arsW += 1
System.Threading.Thread.Sleep(20)
End While
End Sub
Private Sub DecSweep()
While True
arsW -= 1
System.Threading.Thread.Sleep(20)
End While
End Sub