C# 多线程之新线程延时执行
- using System;
- using System.Threading;
-
- namespace ConsoleApplication1
- {
- class Program
- {
- public static ManualResetEvent mre = new ManualResetEvent(false);
-
- staticvoid Main(string[] args)
- {
- Thread newThread = new Thread(new ThreadStart(NewThread));
- newThread.Name = "新线程";
- newThread.Start();
-
- mre.Set();
-
- Console.WriteLine("Main 函数结束。");
- }
-
- staticvoid NewThread()
- {
- Console.WriteLine("新线程: waiting for an event");
- mre.WaitOne();
- Console.WriteLine("新线程: got an event");
-
- Console.WriteLine(DateTime.Now);
- Thread.Sleep(2000); //延时两秒
- Console.WriteLine(DateTime.Now);
-
- Console.WriteLine("新线程已执行完。。");
- Console.WriteLine();
- }
- }
- }
补充:软件开发 , C# ,