.net 5 ++ 版本 不支持 Thread.Abort
所以,采用另外一种方案
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30class Program { static void Main(string[] args) { var thread = new Thread(Test); thread.Start(); SpinWait.SpinUntil(() => false, 5 * 1000); thread.Interrupt(); Console.WriteLine("Hello World!"); Console.ReadLine(); } static void Test() { try { int i = 0; while (true) { Thread.Sleep(1000); Console.WriteLine(i++); } } catch (Exception e) { Console.WriteLine(e.Message); } } }
完美解决问题.
最后
以上就是跳跃外套最近收集整理的关于.net 5 .net 6 Thread.Abort is not supported的全部内容,更多相关.net内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复