vb.net中线程委托的简单实例

vb.net中线程委托的简单实例,第1张

概述[原帖地址]http://topic.csdn.net/u/20111019/17/ac098c48-ed25-4e1f-acd0-ec192ca44eac.html '原先错误的写法!-------------------------Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Event

[原帖地址]http://topic.csdn.net/u/20111019/17/ac098c48-ed25-4e1f-acd0-ec192ca44eac.html

'原先错误的写法!-------------------------Private Sub button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button1.Click    Dim MyThread As New System.Threading.Thread(AddressOf sum)    MyThread.Start()End SubPrivate Sub sum()    Dim i,sum As Integer    For i = 0 To 100        sum += i    Next    Me.Text = CStr(sum)  '在这里就会报错,教我"如何跨线程调用windows窗体控件",表示没看懂End Sub-------------------------------------'正确的线程委托写法-------------------------------------Private Delegate Sub myDelegate(ByVal myString As String) '自定义一个委托Private Sub SetwindowText(ByVal myString As String) '与委托相同签名的函数或过程Me.Text = myStringEnd SubPrivate Sub button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button1.ClickDim MyThread As New System.Threading.Thread(AddressOf sum)MyThread.Start()End SubPrivate Sub sum()Dim i,sum As IntegerFor i = 0 To 100sum += iNextMe.Invoke(New myDelegate(AddressOf SetwindowText),sum.ToString) '委托的调用End Sub
总结

以上是内存溢出为你收集整理的vb.net中线程委托的简单实例全部内容,希望文章能够帮你解决vb.net中线程委托的简单实例所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1290286.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存