多线程系列 线程池ThreadPool
上一篇文章我们总结了多线程最基础的知识点Thread,我们知道了如何开启一个新的异步线程去做一些事情。可是当我们要开启很多线程的时候,如果仍然使用Thread我们需要去管理每一个线程的启动,挂起和终止,显然是很麻烦的一件事情。还好.net framework为我们提供了线程池ThreadPool来帮助我们来管理这些线程,这样我们就不再需要手动地去终止这些线程。这一篇文章就让我们来学习一下线程池ThreadPool吧。关于它我想从以下几个方面进行总结。
- 认识线程池ThreadPool
- ThreadPool的用法
ThreadPool类是一个静态类,你不能也不必要生成它的对象。而且一旦使用该方法在线程池中添加了一个项目,那么该项目是无法取消的。这里你无需自己建立线程,我们只需要把要做的工作写成函数,然后作为参数传递给ThreadPool.QueueUserWorkItem()方法就行了,传递的方法是依靠WaitCallBack代理对象,而线程的建立,管理和运行等工作都是由系统自动完成的,你无须考虑那些复杂的细节问题了。
我现在在之前的例子的基础上,使用线程池ThreadPool来实现。代码如下。
namespace ThreadDemo
{
class Program
{
static void Main(string[] args)
{
// 使用ThreadPool实现
Fish fish1 = new Fish { Name = "小黄鱼" };
Fish fish2 = new Fish { Name = "大鲨鱼" };
Fish fish3 = new Fish { Name = "灯笼鱼" };
Fish fish4 = new Fish { Name = "红鲤鱼" };
Fish fish5 = new Fish { Name = "灯笼鱼" };
ThreadPool.QueueUserWorkItem(f => { fish1.Move(); }); //lambda表达式
ThreadPool.QueueUserWorkItem(f => { fish2.Move(); });
ThreadPool.QueueUserWorkItem(f => { fish3.Move(); });
ThreadPool.QueueUserWorkItem(f => { fish4.Move(); });
ThreadPool.QueueUserWorkItem(f => { fish5.Move(); }); Console.ReadKey();
}
} /// <summary>
/// 鱼
/// </summary>
public class Fish
{
public string Name { get; set; } public int Score { get; set; } public Fish()
{
} public void Move()
{
Console.WriteLine(string.Format("{0}在游来游去...", Name));
}
}
}
程序运行结果如下。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZUAAADuCAIAAAB+qw3aAAAZH0lEQVR4nO2cZ5gVRdqG5++6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D/AgC4CvIvAICrIP8CALgK8i8AgKsg/wIAuAryLwCAqyD/AgC4CvIvAICrIP8CALgK8i8AgKsg/wIAuAryLwCAqyD/AgC4CvIvAICrIP8CALgK8i8AgKsg/wIAuAryLwCAqyD/AgC4CvIvAICrIP8CALgK8i8AgKsg/wIAuAryLwCAqyD/AgC4CvIvAICrIP8CALgK8i8AgKsg/wIAuAryLwCAqyD/AgC4CvIvAICrIP8CALgK8i8AgKsg/wIAuApzDrEUFhbCXwCApMDMQ4F5Cf4CACQF0Tz2An8BAJIF/AUAcBX4CwDgKvAXAMBVRPOYOsBfAIAkIuVf6lH4CwCQUNTnR/EQ/AUASC7a9a8C3Xut8BcAIFlg/R4A4CrwFwDAVeAvAICrwF8AAFdhwiECfwEAEkRhQKj+omR0vATtj4JCL+x3tDzsf3SHbS63QX+yIX4fqP7yaATtDwAd6akBWye2gX6yMfqLEi5ofxQUeuG/o+UJmJbY+m7FCuUnG+JXAv5CcaYg/3J0S//JBi1Z+auA8HdJKChRFeRfbm3FCiuqMcSfbKBfBulCgf3FvjIwjQP+Qom8IP9ydMuLVhrlwf3leV5RUZEYP5i/+Fee9t8wFJQIC/Ivt7ZihRVfb1AKk1d4f4mvbJjGAX+hRF6Qfzm65cWkDrq/RHmJ8ZF/oSS9IP9yaytWWMky//KUzCukv8qx/oWS84L8y9EtL9msf0nyymr9i4/G/huGghJhQf7l1lassBL6+0dVXhH4yzIO+Asl8oL8y9Et/SerLSZ5ifHhL5SkF+Rfbm3FCuUnqz1kkpd0IfgLJekF+ZejW/pPVioWeQV7fiwiE7Q/AHSQfzm0DeENuryK6P4CIDnU+LTElrgN8ZMNJC+Sv8oJ6R8KCgpK7ouPvzwAAEgwNn+hoKCgJL/AXygoKK6WE/wV/vshAACoCY77K6KviQAAIKd4nldQg0txAACQDf8PCSzMQwjh6gUAAAAASUVORK5CYII=" alt="" />
eg2:
说明:将方法排入队列以便执行,WaitCallback,表示要执行的方法。如果将方法成功排入队列,则为 true;否则为 false。
示例:addtest方法需要比较长的时间来响应,因此在button1_Click被点击以后,程序会失去响应,使用ThreadPool.QueueUserWorkItem 后,页面会继续响应其他时间,等addtest执行结束后,响应结果。
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Button Height="23" HorizontalAlignment="Left" Margin="9,23,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click">ButtonOne</Button>
<Button Height="23" Margin="102,23,101,0" Name="button2" VerticalAlignment="Top" Click="button2_Click">ButtonTwo</Button>
</Grid>
</Window>
{
ThreadPool.QueueUserWorkItem(new WaitCallback(addtest),"Testaa");
//addtest();
}
private void addtest(object aa)
{
long result=0;
for (int i = 0; i < 1000000000; i++)
{
result += i;
}
MessageBox.Show(result.ToString()+aa.ToString());
}
private void button2_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("two");
}
多线程系列 线程池ThreadPool的更多相关文章
- Java多线程系列——线程池简介
什么是线程池? 为了避免系统频繁地创建和销毁线程,我们可以让创建的线程进行复用.用线程时从线程池中获取,用完以后不销毁线程,而是归还给线程池. JDK 对线程池的支持 为了更好的控制多线程,JDK 提 ...
- Java多线程系列——线程池原理之 ThreadPoolExecutor
ThreadPoolExecutor 简介 ThreadPoolExecutor 是线程池类. 通俗的讲,它是一个存放一定数量线程的线程集合.线程池允许多个线程同时运行,同时运行的线程数量就是这个线程 ...
- 多线程系列(2)线程池ThreadPool
上一篇文章我们总结了多线程最基础的知识点Thread,我们知道了如何开启一个新的异步线程去做一些事情.可是当我们要开启很多线程的时候,如果仍然使用Thread我们需要去管理每一个线程的启动,挂起和终止 ...
- C#多线程学习 之 线程池[ThreadPool](转)
在多线程的程序中,经常会出现两种情况: 一种情况: 应用程序中,线程把大部分的时间花费在等待状态,等待某个事件发生,然后才能给予响应 这一般使用ThreadPo ...
- C# -- 使用线程池 ThreadPool 执行多线程任务
C# -- 使用线程池 ThreadPool 执行多线程任务 1. 使用线程池 class Program { static void Main(string[] args) { WaitCallba ...
- C#多线程学习 之 线程池[ThreadPool]
在多线程的程序中,经常会出现两种情况: 一种情况: 应用程序中,线程把大部分的时间花费在等待状态,等待某个事件发生,然后才能给予响应 这一般使用ThreadPo ...
- [转]C#多线程学习 之 线程池[ThreadPool]
在多线程的程序中,经常会出现两种情况: 一种情况: 应用程序中,线程把大部分的时间花费在等待状态,等待某个事件发生,然后才能给予响应 这一般使用ThreadPo ...
- python中多进程multiprocessing、多线程threading、线程池threadpool
浅显点理解:进程就是一个程序,里面的线程就是用来干活的,,,进程大,线程小 一.多线程threading 简单的单线程和多线程运行:一个参数时,后面要加逗号 步骤:for循环,相当于多个线程——t=t ...
- 多线程Thread,线程池ThreadPool
首先我们先增加一个公用方法DoSomethingLong(string name),这个方法下面的举例中都有可能用到 #region Private Method /// <summary> ...
随机推荐
- JVM学习总结五(番外)——VisualVM
距离上次介绍Jconsole已经时隔两周了,这期间由于工作中要用go来做一个新项目,所以精力都用在入门go上了,不过发现go语言用起来真的挺不错的,比python感觉还好点,大家没事可以了解下. ...
- JVM学习总结一——内存模型
JVM是java知识体系的基石之一,任何一个java程序的运行,都要借助于他.或许对于我这种初级程序员而言,工作中很少有必要刻意去关注JVM,然而如果能对这块知识有所了解,就能够更清晰的明白程序的运行 ...
- Your First ASP.NET 5 Application on a Mac
Your First ASP.NET 5 Application on a Mac By Daniel Roth, Steve Smith, Rick Anderson ASP.NET 5 is cr ...
- [转]insmod
[转]insmod http://www.cnblogs.com/amaoxiaozhu/archive/2013/03/08/2950002.html 在Linux下,驱动程序是内核的一部分,运行在 ...
- Labview实现单边带信号调制(SSB)[滤波法]
Labview实现单边带信号调制(SSB)[滤波法] 首先用信号仿真器得到一个被调制信号m(t),以及载波信号,该实验选择正弦信号作为载波信号. 根据调制器模型 得到一个结果信号. 其中,H(w)的选 ...
- 动态链接库知识点归纳之一(DLL概念,如何建立,如何使用,如何优化,如何查看)
简单的总结一些动态链接库的一些知识,方便以后查找. 首先,新建一个动态链接库 (1) 打开编辑器,选择WIN32项目, dll,如下图,项目名字为:test,选择空项目.如下图 (2) ...
- 51nod 1109 01组成的N的倍数
用01 组成 N的最小倍数 这个BFS搜索就好. 类似这道: ZOJ Problem Set - 1530 每次 要么是0 要么是1, 记入余数,和前驱. #include<bits/stdc ...
- React + Reflux
React + Reflux 渲染性能优化原理 作者:ManfredHu 链接:http://www.manfredhu.com/2016/11/08/23-reactRenderingPrinc ...
- js之变量和作用域
JS的变量和其他语言的变量有很大区别.JS变量时“松散型”的,决定它只是在特定时间用于保存特定的一个名字而已.由于不存在变量要保存何种数据类型,变量的值和其数据类型可以在脚本的生命周期内改变. JS两 ...
- MySQL 分组
MySQL GROUP BY 语句 GROUP BY 语句根据一个或多个列对结果集进行分组. 在分组的列上我们可以使用 COUNT, SUM, AVG,等函数. GROUP BY 语法 SELECT ...