当前位置: 移动技术网 > IT编程>开发语言>c# > C#线程池操作方法

C#线程池操作方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例讲述了c#线程池操作方法。分享给大家供大家参考。具体如下:

static void main(string[] args)
{
 //设置线程池中的线程数最大为1000,
 //第一个为工作者线程,第二个为i/o线程
 threadpool.setmaxthreads(1000, 1000);
 for (int i = 0; i < 10;i )
 {
  threadpool.queueuserworkitem(new waitcallback(showmessage), string.format("当前编号{0}",i));
 }
 console.readline();
}
//带参数 无返回值
static void showmessage(object x)
{
 string current = string.format("当前线程id为{0}", system.
  threading.thread.currentthread.managedthreadid);
 //等待1秒钟
 system.threading.thread.sleep(1000);
 console.writeline(string.format("{0},输入为{1}", current, x));
}

希望本文所述对大家的c#程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网