如何使用线程池 [英] How to use Thread Pool

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

问题描述




当我运行此代码时,控制台上没有任何显示,但是当我调试时它会显示输出。

请解释为什么会发生这种情况?如何在线程完成任务时获取信息?



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); }
     }
 }

推荐答案

这篇关于如何使用线程池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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