|
楼主 |
发表于 2013-7-22 20:24:31
|
显示全部楼层
- private static Semaphore sem = new Semaphore(10, 10);
-
- static void Main(string[] args)
- {
- for (int i = 0; i < 100; i++)
- {
- Thread t = new Thread(new ThreadStart(delegate
- {
- Bg(i);
- }));
- t.Start();
- sem.WaitOne();
- Thread.Sleep(10);
- }
- Console.ReadKey();
- }
- public static void Bg(int i)
- {
- string a= Begin(i);
- Console.WriteLine("返回值输出 " + a);
- }
-
-
-
- public static string Begin(int i)
- {
-
- Thread.Sleep(5000);
- Console.WriteLine("参数输出 "+i.ToString());
- sem.Release();
- return i.ToString();
- }
复制代码 贴一下代码,本人菜鸟一个,大家不要喷,要是还有啥好的办法望赐教~!!! |
|