我是靠谱客的博主 跳跃外套,这篇文章主要介绍.net 5 .net 6 Thread.Abort is not supported,现在分享给大家,希望可以做个参考。

.net 5 ++ 版本  不支持 Thread.Abort

所以,采用另外一种方案

    class 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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部