2008年9月8日 星期一

vb.net 多執行緒控制物件Label跟button

Dim MainThread As New Threading.Thread(AddressOf MainProcess)'定義新的執行序.......
MainThread.Start()'執行序啟動'跨執行序呼叫元件,label 跟 button'-------------------
Public Sub SetButton(ByVal [text] As String, ByVal BTN As Button)
' InvokeRequired required compares the thread ID of the
' calling thread to the thread ID of the creating thread.
' If these threads are different, it returns true.
If BTN.InvokeRequired Then
Dim d As New SetButtonCallback(AddressOf SetButton)
BTN.Invoke(d, New Object() {Convert.ToString([text]), BTN})
Else
BTN.Text = [text]
End If
End Sub
Delegate Sub SetButtonCallback(ByVal [text] As String, ByVal BTN As Button)'----------------------------------------Label
Public Sub SetText(ByVal [text] As String, ByVal Lab As Label)
' InvokeRequired required compares the thread ID of the
' calling thread to the thread ID of the creating thread.
' If these threads are different, it returns true.
If Lab.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf SetText)
Lab.Invoke(d, New Object() {Convert.ToString([text]), Lab})
Else
Lab.Text = [text]
End If
End Sub
Delegate Sub SetTextCallback(ByVal [text] As String, ByVal Lab As Label)

1 則留言:

  1. Heya i'm for the first time here. I found this board and I in finding It truly helpful & it helped me out a lot. I hope to provide one thing back and help others like you helped me.
    My page - perfumes

    回覆刪除