public static void Main(string[] args)
        {
            Thread mathThread = new Thread(new ThreadStart(TestThread));            mathThread.Start();
            Thread.Sleep(1000);
        }        static void TestThread()
        {
            Console.WriteLine("Test Thread");            return;          
        }
为什么程序不是循环输出Test Thread?而是过1秒自动结束了?如何让线程休息1秒自动循环执行?不是很了解线程工作原理,请大家指教。

解决方案 »

  1.   

    晕,你的新线程执行完了就结束了啊  static void TestThread() 
            { 
    while(true)
    {
                Console.WriteLine("Test Thread"); 
    Thread.Sleep(1000);
    }
              return;//要不要一样    
            } 
      

  2.   

    那如何让程序定时执行TestThread(),即使return。
    把Thread Sleep(1000),放在TestThread()的外部,如何实现???
      

  3.   

    或者说只要让TestTread()循环定时执行就行。
      

  4.   


        public static void Main(string[] args) 
            { 
                Thread mathThread = new Thread(new ThreadStart(TestThread));             mathThread.Start(); 
                mathThread.Join();
            }         static void TestThread() 
            { 
                Console.WriteLine("Test Thread");             return;          
            } 
      

  5.   

    嘿嘿,这样就行了,谢谢CSTOD的提示。
    public static void Main(string[] args) 
            { 
                Thread mathThread = new Thread(new ThreadStart(RecycleTestThread));             mathThread.Start();         }         Static void RecycleTestThread()
            {
              while(true)
              {
                TestThread();
                Thread.Sleep(1000);
              }
            }        static void TestThread() 
            { 
                Console.WriteLine("Test Thread");             return;          
            }