-1
这是我的代码:VB.Net杀多线程功能
For i As Integer = 0 to 20
mythread = New System.Threading.Thread(AddressOf myfunction)
mythread.Start()
Next
我要杀死所有正在运行的MyFunction()
我尝试了所有的线程:
For Each hello123 As System.Threading.Thread(AddressOf myfunction)
thread.abort(hello123)
Next
但想出了带有错误(在AddressOf):
数组边界不能出现在类型说明符中。
[**您不应该使用'Thread.Abort()'来停止线程**](https://stackoverflow.com/a/1560567/3740093)。您必须在** _'myfunction'内部实现自己的检查_ **,以便在必要时终止线程。例如:'如果IsThread1Running = False Then Return'。 - 请考虑使用[**任务**](https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/task-cancellation)。 –
至于访问循环中的每个线程:如果您将自己的线程存储在某处,例如[**'List(Of T)'**](https:// msdn .microsoft.com/EN-US /库/ 6sh2ey19(v = vs.110)的.aspx)。 –
我已经添加了**直到hey = 0 **循环到我的函数(嘿是整数),所以当我按下停止按钮时,函数会自动停止并且工作正常,但是我想知道是否有更好的解决方案。 –