在同一时间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"

 

相关文章:

  • 2022-01-29
  • 2021-09-04
  • 2021-10-17
  • 2022-12-23
  • 2021-05-20
  • 2021-06-18
  • 2021-11-04
  • 2021-08-05
猜你喜欢
  • 2022-01-08
  • 2021-12-20
  • 2021-09-30
  • 2021-04-26
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
相关资源
相似解决方案