请教多任务该如何写法
程序的目标,按下按钮,按数组元素的个数动态创建相应的计算任务,并把数组元素传入相应的任务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
望高手不吝赐教,万分感谢
我的程序如下
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
望高手不吝赐教,万分感谢
...全文
相关推荐
易语言-易语言简单多线程写法
通过学习和实践“易语言简单多线程写法”,你可以掌握如何在易语言环境下实现多任务并行,提高程序的性能和用户体验。对于想要深入学习易语言的程序员来说,这是一个非常有价值的参考资料。
簡單的先佔多工核心寫法for AVR
标题 "簡單的先佔多工核心寫法for AVR" 提供了我们正在讨论的主题,即在AVR微控制器上实现一个简单的抢占式多任务操作系统核心。
labview多通道多任务同步
**多任务并行处理**: 在LabVIEW中,多任务处理可以通过并行结构(如并行循环、子VI并行运行等)实现。每个任务可以看作是一个独立的VI或子VI,它们可以在同一时间运行,提高系统的执行效率。
多任务学习
相比单任务学习,多任务学习能够利用更多的信息,使模型在面对新任务时具备更好的适应性。2. **数据创建** 在多任务学习中,数据的准备至关重要。
Java中List for循环的6种写法总结(推荐)
Java中List for循环的6种写法总结了六种不同的写法,每种写法都有其优缺点,开发中可以根据实际情况选择合适的写法。


