[原帖地址]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中线程委托的简单实例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)