一个接一个地运行线程 [英] run thread one after another

查看:57
本文介绍了一个接一个地运行线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何完成第一个线程任务后如何启动第二个线程.

How to start the second thread after finishing of first thread task.

推荐答案

简单示例

hi simple Example

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 [




further Ref:

http://www.albahari.com/threading/part2.aspx[^]

regards
sarva


http://www.c-sharpcorner. com/UploadFile/mgold/MultithreadingIntro10062005000439AM/MultithreadingIntro.aspx [ ^ ]


这篇关于一个接一个地运行线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆