线程基础_创建线程、挂起线程、线程等待、中止线程+

创建线程

Thread t=new Thread(方法名称)
t.start();

暂停线程

Thread.Sleep(TimeSpan.FromSeconds(2));

线程等待

t.Join();

中止线程

t.Abort();
CancellationToken();

线程优先级
t.Priority = ThreadPriority.Highest;

前台线程和后台线程
t.IsBackground=true;

在线程Start()前i已经等于20

int i=10;
var threadone=new Thread(()=>printNumber(i));
i=20;
var threadtwo=new Thread(()=>printNumber(i));
threadone.Start();
threadtwo.Start();
posted @ 2023-06-15 08:20  libaisheng9723  阅读(15)  评论(0)    收藏  举报