本文介绍了一个接一个地运行线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何完成第一个线程任务后如何启动第二个线程.
How to start the second thread after finishing of first thread task.
推荐答案
class TheClub // No door lists!
{
static SemaphoreSlim _sem = new SemaphoreSlim (3); // Capacity of 3
static void Main()
{
for (int i = 1; i <= 5; i++) new Thread (Enter).Start (i);
}
static void Enter (object id)
{
Console.WriteLine (id + " wants to enter");
_sem.Wait();
Console.WriteLine (id + " is in!"); // Only three threads
Thread.Sleep (1000 * (int) id); // can be here at
Console.WriteLine (id + " is leaving"); // a time.
_sem.Release();
}
}
进一步的参考:
http://www.albahari.com/threading/part2.aspx [ ^ ]
问候
sarva
further Ref:
http://www.albahari.com/threading/part2.aspx[^]
regards
sarva
这篇关于一个接一个地运行线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!