110,530
社区成员
发帖
与我相关
我的任务
分享
'窗体
Imports System.Threading.Tasks
Imports System.Threading
Public Class Form1
Public WithEvents cls As Class1
Private Sub xxxxxxx(ByVal s As String)
Me.Invoke(Sub()
TextBox1.Text = s
End Sub)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'AddHandler xxx, AddressOf xxxxxxx
'test("aaa")
For i = 1 To 3
Task.Factory.StartNew(Sub()
yyy("a")
End Sub)
Next
End Sub
End Class
'模块
Imports System.Threading.Tasks
Imports System.Threading
Module Module1
Public Event xxx(a As String)
Public Sub test(a As String)
RaiseEvent xxx(a)
End Sub
Public Sub yyy(ByVal s As String)
Dim j As Integer
For j = 1 To 5
Task.Factory.StartNew(Sub(j1)
Task.Factory.StartNew(Sub(j2)
Do
Application.OpenForms.Item("Form1").Invoke(Sub()
Application.OpenForms.Item("Form1").Controls.Item("TextBox1").Text = j2 & "|" & s & "|" & Now.ToString("yyyy-MM-dd HH:mm:ss")
End Sub)
Thread.Sleep(100 * Rnd())
Loop
End Sub, j1)
End Sub, j)
Next
End Sub
End Module
Imports System
Module Program
Sub Main(args As String())
AddHandler X.啊哈, AddressOf xx
X.test("aaa")
Console.WriteLine("按任意键结束......")
Console.ReadKey()
End Sub
Sub xx(x As String)
Console.WriteLine(x)
End Sub
End Module
Module X
Public Event 啊哈(a As String)
Sub test(a As String)
RaiseEvent 啊哈(a)
End Sub
End Module