Sleep中的千分之一

到底是Sleep的时间,到唤醒需要千分之一秒,还是执行下一步用了千分之一秒?

总之,我决定Sleep(1000-1)都减去一豪秒.代码如下.

using System;
using System.Threading;

namespace ThreadPool1
{
 /// <summary>
 /// Class1 的摘要说明。
 /// </summary>
 class Class1
 {
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
   //
   // TODO: 在此处添加代码以启动应用程序
   //
   // Queue the task.
   
   ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));
       
   Console.WriteLine("Main thread does some work, then sleeps."+DateTime.Now.ToString("h:mm:ss.fffffff"));
   // If you comment out the Sleep, the main thread exits before
   // the thread pool task runs.  The thread pool uses background
   // threads, which do not keep the application running.  (This
   // is a simple example of a race condition.)
   Thread.Sleep(999);

   Console.WriteLine("Main thread exits."+DateTime.Now.ToString("h:mm:ss.fffffff"));

  }

  // This thread procedure performs the task.
  static void ThreadProc(Object stateInfo)
  {
   // No state object was passed to QueueUserWorkItem, so
   // stateInfo is null.
   Console.WriteLine("Hello from the thread pool."+DateTime.Now.ToString("h:mm:ss.fffffff"));
  }

 }
}

posted @ 2005-06-14 21:07  wanghualiang  阅读(280)  评论(0编辑  收藏  举报