我是靠谱客的博主 跳跃外套,最近开发中收集的这篇文章主要介绍.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 5 .net 6 Thread.Abort is not supported所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部