我正在努力理解为什么没有输出使用以下内容:
class Program
{
static int m_Active = 500;
static void Main(string[] args)
{
ThreadPool.SetMaxThreads(5, 5);
Enumerable.Range(1, m_Active).ToList<int>()
.ForEach(i => ThreadPool.QueueUserWorkItem((o) => { DoWork(i); }));
}
private static void DoWork(int i)
{
new Action(() => { Console.WriteLine(i); }).Invoke();
if (Interlocked.Decrement(ref m_Active).Equals(0))
new Action(() => { Console.WriteLine("Done"); }).Invoke();
}
}
Run Code Online (Sandbox Code Playgroud)
因为您的程序在有任何时间执行线程之前终止.添加简单
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)
在Main方法的最后应该做的很好.
| 归档时间: |
|
| 查看次数: |
111 次 |
| 最近记录: |