Thread.Sleep(0)的含义
经常有朋友问:Thread.Sleep(0)的含义
我给朋友解答,顺便写了一个例程,供大家讨论
Thread.Sleep(0):Specify zero (0) to indicate that this thread should be suspended to allow other waiting threads to execute.
例子:
static void Main(string[] args)
{
T=new Thread(new ThreadStart(MyCalculate));
T.Start();
DateTime s=DateTime.Now;
Thread.Sleep(0);//大家可以注释这条语句察看结果的不同
T.Abort();
TimeSpan e=DateTime.Now-s;
Console.WriteLine(e+"thread end");
}
public static void MyCalculate()
{
int i=0;
while(true)
{
i++;
Console.WriteLine(i+"thread start");
}
}