在同一时间CPU只能执行一个线程
所以只有当本线程挂起或结束时才会执行其他线程
代码
class Program
{
public void Method1()
{
Console.WriteLine("Method1 is the starting point of excution of the thread");
}
static void Main(string[] args)
{
Program newp = new Program();
Thread thread1 = new Thread(new ThreadStart(newp.Method1));
thread1.Start();
//1位置
Console.WriteLine("The excution of Sample Thread has started");
//2位置
thread1.Abort();
Console.ReadLine();
}
}
如果把Thread.Sleep(100);放在1位置则先输出结果为"Method1 is the starting point of excution of the thread"
如果把Thread.Sleep(100);放在2位置则先输出结果为"The excution of Sample Thread has started"