开通VIP,畅享免费电子书等14项超值服
首页
好书
留言交流
下载APP
联系客服
2013.09.04
class
Program
{
static
AutoResetEvent are =
new
AutoResetEvent(
false
);
int
ticks = 100;
void
Main(
string
[] args)
Thread t1 =
Thread(
ThreadStart(Saling));
Thread t2 =
Thread t3 =
Thread t4 =
t1.Name =
"1"
;
t2.Name =
"2"
t3.Name =
"3"
t4.Name =
"4"
t1.Start();
t2.Start();
t3.Start();
t4.Start();
Console.ReadKey();
}
public
Saling()
Thread th = Thread.CurrentThread;
//得到当前线程
while
(ticks>-1)
Console.WriteLine(
"ThreadName:"
+th.Name+
" 票数:"
+ticks--);
are.Set();
//终止当前线程,让下一个线程来执行
Thread.Sleep(50);
微信登录中...请勿关闭此页面