本文介绍了如何使用线程池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
当我运行此代码时,控制台上没有任何显示,但是当我调试时它会显示输出。
请解释为什么会发生这种情况?如何在线程完成任务时获取信息?
Hi
When i run this code then nothing display on console but when i debug then it display the output.
Please explain why this happen? How i can get info when the Thread complete the task ?
public class TestClass
{
static void Main()
{
ThreadPool.SetMaxThreads(5, 5);
for (int x = 0; x < 10; x++)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(printnum), x);
}
Console.ReadKey();
}
public static void printnum(object n)
{
Console.WriteLine("Call " + n);
for (int i = 0; i < 10; i++) { Console.WriteLine(i); }
}
}
推荐答案
这篇关于如何使用线程池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!