gpt4 book ai didi

vb.net - 多个背景工作人员vb.net

转载 作者:行者123 更新时间:2023-12-03 12:53:03 26 4
gpt4 key购买 nike

我需要使用backgroundwoker在后台运行多个任务

例如dim mybacgroundwokers(10) as backgroundwoker
在backgroundworker事件过程中,我可以做这样的事情吗,因为我不知道

mybackgroundwoker_dowork(,,index)

select case index
case 1
'dowork for backgroundworker1
case 2
'dowork for backgroundworker2
end select

或我如何处理多个背景工作人员

如果backgroundworker不可能做到这一点,那么我该如何使用线程多线程处理呢?

谢谢

最佳答案

您应该使用多个具有适当名称的Backgroundworkers,例如:

Dim CountSheepBackgroundWorker As BackgroundWorker WithEvents
Dim CountStarsBackgroundWorker As BackgroundWorker WithEvents
Dim StackEggsBackgroundWorker As BackgroundWorker WithEvents

如果您绝对要使用数组,Visual Studio将无法帮助您使用DoWork Subs:
Dim MyBackgroundWorkers(9) As BackgroundWorker
' Add first
MyBackgroundWorkers(0) = new BackgroundWorker
AddHandler MyBackgroundWorkers(0), AddressOf FirstBackgroundWorker_DoWork
MyBackgroundWorkers(0).RunWorkerAsync()
' Add second etc

关于vb.net - 多个背景工作人员vb.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5357636/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com