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