當前位置:編程學習大全網 - 編程軟體 - 求助vb.net處理多線程的問題,想用委托來做以下代碼。兩個button控件和兩個textbox控件。

求助vb.net處理多線程的問題,想用委托來做以下代碼。兩個button控件和兩個textbox控件。

Public Class Form1

Delegate Sub MySubDelegate(ByVal txt As String,ByVal num as integer)

Private Sub txtW(ByVal txt As String,ByVal num as integer)

Dim msgd As New MySubDelegate(AddressOf Me.txtW1)

Me.Invoke(msgd, txt,num)

End Sub

Private Sub txtW1(ByVal txt As String,ByVal num as integer)

if num=1 then

TextBox1.Text=txt

else

TextBox2.Text=txt

end if

End Sub

Dim t1, t2 As Threading.Thread

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub autoAction1()

For i = 0 To 100

Delay(10)

txtw(i.ToString,1)

Next

t1.Abort()

End Sub

Private Sub autoAction2()

For i = 0 To 100

Delay(10)

txtw(i.ToString,2)

Next

t2.Abort()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

t1 = New Threading.Thread(AddressOf autoAction1)

t1.Start()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

t2 = New Threading.Thread(AddressOf autoAction2)

t2.Start()

End Sub

Public Sub Delay(ByRef Interval As Double)? 'Interval單位為毫秒

Dim time As DateTime = DateTime.Now

Dim Span As Double = Interval * 10000

While ((DateTime.Now.Ticks - time.Ticks) < Span)

Application.DoEvents()

End While

End Sub

End Class

  • 上一篇:青島中考特長生加分政策
  • 下一篇:光伏工程技術是學什麽的
  • copyright 2024編程學習大全網