0
我有一个VB.NET控制台程序,其中我在for循环中启动了10个线程。 循环完成后,10个线程将运行,我需要代码暂停(在完成for-loop之后),直到所有线程完成/中止为止。在循环中创建线程并等待所有线程完成/中止
我该怎么办?
这里是例子:
Private Sub TheProcessThread()
While True
'some coding
If 1 = 1 Then
End If
End While
Console.WriteLine("Aborting Thread...")
Thread.CurrentThread.Abort()
End Sub
Sub Main()
Dim f as Integer
Dim t As Thread
For f = 0 To 10
t = New Thread(AddressOf TheProcessThread)
t.Start()
Next
' HERE !! how I can be sure that all threads are finished/aborted for continue with the code below ?
' more vb.net code...
End Sub
请不要永远永远永远调用'Thread.CurrentThread.Abort()'** **除非你是试图强行关闭你的应用程序。调用'.Abort()'可以使.NET运行时处于无效状态。 – Enigmativity