请教多任务该如何写法
程序的目标,按下按钮,按数组元素的个数动态创建相应的计算任务,并把数组元素传入相应的任务task
我的程序如下
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
ReDim startTest(Val(TextBox2.Text) - 1)
ReDim totalTest(TestCharTotal - 1)
Dim j As Integer = 0, i As Integer = 0
If CheckBox1.Checked Then
Array.Copy(sz, 0, totalTest, j, sz.Length)
j = j + sz.Length
End If
If CheckBox2.Checked Then
Array.Copy(xxzm, 0, totalTest, j, xxzm.Length)
j = j + xxzm.Length
End If
If CheckBox3.Checked Then
Array.Copy(dxzm, 0, totalTest, j, dxzm.Length)
j = j + dxzm.Length
End If
If CheckBox4.Checked Then
Array.Copy(tszf, 0, totalTest, j, tszf.Length)
End If
j = Int(totalTest.Length / startTest.Length)
For i = 0 To startTest.Length - 1
startTest(i) = totalTest(i * j)
Next
Dim tasks = startTest.[Select](Function(st) ProcessAsync(st)).ToList()
Task.WhenAll(tasks) 执行到这里出错,检查tasks中的元素都是null
End Sub
Private Function ProcessAsync(st As String) As Task
BeginInvoke(New Action(Sub()
TextBox4.AppendText(st & vbCrLf)
End Sub))
End Function
望高手不吝赐教,万分感谢