在 while True 块中运行线程应该没问题。一旦它为假,您就可以遍历线程并调用 thread.abort(),即使有时使用 abort 不是一个好主意。使用线程列表可能会有所帮助。我不知道您是如何创建线程的,但这应该很容易理解。
Dim listThreads As List(Of Threading.Thread)
'create/instantiate your threads adding them to the collection something like the following
For i = 1 To numberofthreadsyouneed
Dim tempThread As Threading.Thread = New Threading.Thread
tempThread.Start()
tempThread.Add(tempThread)
next
不要使用 while 块,只需执行 Try catch。在 catch 内迭代列表以中止线程
Catch ex As Exception
For each Thread in listThreads
Thread.Abort()
Next
end Try