启动一个线程是调用 start() 方法,new一个ThreadStart class, 然后,把ThradStart class对象传给Thread类,Thread类start()

View Code
   public class ThreadWork
    {
        public static void DoWork()
        {
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("Working thread..{0}", i);
                Thread.Sleep(100);
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            ThreadStart myStart = new ThreadStart(ThreadWork.DoWork);
            Thread myThread = new Thread(myStart);

            //启用一个Thread
            myThread.Start();
        }
    }

 

相关文章:

  • 2022-02-21
  • 2021-08-24
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
  • 2022-12-23
  • 2021-08-23
  • 2022-01-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案