vb.net跨线程调用实例

来源:互联网 发布:冯矿伟网络高级课程 编辑:程序博客网 时间:2024/06/03 16:20

'本例是一个窗口在调用serialport时,回到主线程调用textbox控件

 

’这个是在一个过程中的片段,首先,第一步创建线程

If SerialPort1.BytesToRead <> 0Then
           Rtxt = SerialPort1.Read(Rbyt, 0, 1)
           Dim Nthread As New Threading.Thread(AddressOf ShowTextInvoke)
           Nthread.Start()
       End If

 

'第二步 调用过程

    PublicSub ShowTextInvoke()
       Me.Invoke(New VoidDelegate(AddressOf ShowText))
    End Sub

 

'第三步 声明委托实例

Public Delegate Sub VoidDelegate()

 

'第四步调用真正的过程

    PublicSub ShowText()
       Me.Rtext.Text = Rtxt

    EndSub