请教多任务该如何写法

Y御剑逍遥Y 2020-08-11 04:47:36
程序的目标,按下按钮,按数组元素的个数动态创建相应的计算任务,并把数组元素传入相应的任务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
望高手不吝赐教,万分感谢
...全文
6769 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
清风不拂面 2020-08-19
  • 打赏
  • 举报
回复
sz、xxzm、dxzm、tszf都是全局变量吗?
123工艺品 2020-08-12
  • 打赏
  • 举报
回复
太高深,没看懂

按数组元素的个数动态创建相应的计算任务,并把数组元素传入相应的任务task

建议用数组保存存计算任务的结果,按数组元素个数循环进行计算任务

16,721

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧