目前我通过以下方式(正常方式)创建线程
Public loginThread As Thread
Public loginThreadStart As New ThreadStart(AddressOf LogIntoWhatever)
Public callLoggedIn As New MethodInvoker(AddressOf loggedIn)
但是,我希望能够做的事情是这样的(这显然不起作用,完全是伪代码)
dim i as integer = 0
for i = 0 to i = 25
Public loginThread(i) as Thread
Public loginThreadStart(i) as New ThreadStart(AddressOf LogIntoWhatever)
next i
Public callLoggedIn as new MethodInvoker(AddressOf loggedIn)
我可以将25更改为我想要的任何内容并创建该线程数。他们都将运行一个相同的子,它不会互相打电话,他们不需要彼此的知识。有可能这样吗?如果是这样,朝着解决方案的方向会有所帮助。
提前致谢。
答案 0 :(得分:2)
尝试以下
Public Function RunThreads(count as Integer, start As ThreadStart) As List(Of Thread)
Dim list as New List(Of Thread)
For i = 0 to count -1
Dim thread = new Thread(start)
thread.Start()
list.Add(thread)
Next
Return list
End Function
或使用线程池
Public Sub RunThreads(count as Integer, callBack as WaitCallBack)
For i = 0 To count-1
ThreadPool.QueueUserWorkItem(callBack)
Next
End Sub
答案 1 :(得分:0)
Here是使用简单线程池的示例。
答案 2 :(得分:0)
看看这个Smart Thread Pool,虽然它是用C#编写的。