当前位置:网站首页>C#多线程学习笔记三
C#多线程学习笔记三
2022-06-10 13:42:00 【HollowKnightZ】
ThreadPool
Thread => 一个异步任务开启一个Thread,具有专有性
ThreadPool => 开启异步任务只需要向其借用线程,使用完后归还
ThreadPool的使用方式
ThreadPool.QueueUserWorkItem((obj) =>
{
var Fun = obj as Func<string>;
Console.WriteLine("子线程:" + Thread.CurrentThread.ManagedThreadId + " context:" + Fun());
}, new Func<string>(() => "hello world"));
Console.WriteLine("主线程:" + Thread.CurrentThread.ManagedThreadId);
Console.ReadKey();
ThreadPool与Thread的区别
10个任务,用Thread来做,需要开启10个Thread,如果用ThreadPool来做,只需要将10个任务交给线程池。
Thread的解析函数如下:
~Thread()
{
this.InternalFinalize();
}
从析构函数看到this.InternalFinalize(); 就是说销毁之后,先进入终结器,线程虽然销毁,但是没有被GC(Garbage Collection)回收,该占的资源还是会占。而使用ThreadPool后不会有死线程,而都是默认初始化的。
线程池中的线程:工作线程和IO线程

工作线程:给一般的异步任务执行,不涉及到网络,文件这些IO操作【开 发者调用】
IO线程:一般用在文件,网络IO上。【CLR调用】
总结
ThreadPool可以用8个线程来解决 thread 10个线程做的事情,节省了空间时间。
时间 => 通知各个托管和非托管的DLL
空间 => teb,osthread结构,堆栈
边栏推荐
- Pycharm安装详细教程
- 2022大厂高频软件测试面试真题(附答案)
- Ultra detailed ffmpeg installation and simple use tutorial
- Record common functions in MySQL at work
- [untitled]
- [notes] some records of 74hc573
- markdown设置字体为红色
- 32. Simple test of raspberry pie serial port communication and ultrasonic module ranging
- 小笔记-简单但够用系列_yapi 返回参数 data 应当是 object 类型问题解决记录
- 【笔记】C语言数组指针、结构体+二维数组指针小记
猜你喜欢
![[note] about the problem of insufficient compilation mapping memory in keil](/img/0d/789c7629823600dbc77e62744ef5a1.png)
[note] about the problem of insufficient compilation mapping memory in keil

High performance practical Alibaba sentinel notes, in-depth restoration of Alibaba micro service high concurrency scheme

Z-Wave ecosystem status report in 2022

WT2003H4-16S 语音芯片按键录音及播放应用解析

2022 high frequency software test interview questions of large factories (with answers)

Docker部署一个Redis集群
![[note] the environment for setting up get injectedthread script supplemented by shellcode in Windows Security III and its use](/img/b4/f7838a7e12379190e2bc9b869839f0.png)
[note] the environment for setting up get injectedthread script supplemented by shellcode in Windows Security III and its use
![[notes] some records of 74hc573](/img/52/f6afb71ba1d7dd239c0a02d8a1f41f.png)
[notes] some records of 74hc573

【解决】每次加载已经训练好的模型,生成的向量会有不同

【Multisim仿真】差分放大电路2
随机推荐
CentOS Linux 已死!Oracle Linux 可能是它的更好替代品
技术分享| 快对讲,全球对讲
聊聊消息中间件(1),AMQP那些事儿
Qualcomm has finally begun to develop its own core architecture after learning from the difficulties of assembling chips to maintain its competitive advantage
Ultra detailed ffmpeg installation and simple use tutorial
2022大厂高频软件测试面试真题(附答案)
40 necessary methodologies for large factories
Leetcode-57- insert interval
P3379 【模板】最近公共祖先(LCA)
2022 high frequency software test interview questions of large factories (with answers)
RecyclerView多布局写法,“我的”、“个人中心” 页面经典写法演示
Notes - simple but adequate series_ The Yapi return parameter data should be an object type problem solving record
Cardview usage and properties
为doc2vec生成训练向量的数据集
32. Simple test of raspberry pie serial port communication and ultrasonic module ranging
What are the common automated test frameworks? Shanghai software testing company Amway
Meetup review how Devops & mlops solve the machine learning dilemma in enterprises?
[raise bar C #] how to call the base of the interface
Markdown sets the font to red
[note] about the problem of insufficient compilation mapping memory in keil