C#并行编程【from msdn】

原文链接:http://www.albahari.com/threading/part5.aspx

// Thread.Sleep(TimeSpan.FromHours(1));  // sleep for 1 hour
// Thread.Sleep(500);  // sleep for 500 milliseconds


1.
static bool done;
  static readonly object locker = new object();
 
  static void Main()
  {
    new Thread (Go).Start();
    Go();
  }
 
  static void Go()
  {
    lock (locker)
    {
      if (!done) { Console.WriteLine ("Done"); done = true; }
    }
  }


2.

 Thread t = new Thread(DoWrite);            
 t.Start();
 t.Join();
 Console.WriteLine("Thread t has ended!");

你可能感兴趣的:(Tasks,C#多线程,c#并行编程)