static void Main(string[] args)
        {
            Console.WriteLine("Starting program...");
            Thread t = new Thread(PrintNumbersWithDelay);
            t.Start();
            Thread.Sleep(TimeSpan.FromSeconds(6));
            t.Abort(); // 此处运行报错  
            Console.WriteLine("A thread has been aborted");
            Console.ReadLine();
        }
        static void PrintNumbersWithDelay()
        {
            Console.WriteLine("Starting...");
            for (int i = 1; i < 10; i++)
            {
                Thread.Sleep(TimeSpan.FromSeconds(2));
                Console.WriteLine(i);
            }
        }

 

相关文章:

  • 2021-09-17
  • 2022-12-23
  • 2021-05-16
  • 2022-12-23
  • 2021-09-06
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-18
  • 2021-12-02
  • 2022-12-23
  • 2021-10-12
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
相关资源
相似解决方案