C# Thread join TimeSpan

 static bool isStop = true;
 static void Main(string[] args)
        {
            Thread t = new Thread(PrintX);
            t.Start();
            isStop = t.Join(TimeSpan.FromSeconds(10)); 
            Console.WriteLine("Finished!");
            Console.ReadLine();
        }

       

        static void PrintX()
        {
            for(int i=0;i<Int32.MaxValue;i++)
            {
                if(isStop)
                {
                    Console.WriteLine(i);
                }                
            }
        }

 

posted @ 2020-10-26 10:54  FredGrit  阅读(88)  评论(0编辑  收藏  举报