C#ThreadPool类—多线程

 

标题:ThreadPool Class

地址:https://docs.microsoft.com/zh-cn/dotnet/api/system.threading.threadpool?redirectedfrom=MSDN&view=netframework-4.8

百度关键字看到了:ManualResetEvent

 

Provides a pool of threads that can be used to execute tasks, post work items, process asynchronous I/O, wait on behalf of other threads, and process timers.

提供一个线程池,可用于执行任务、发布工作项、处理异步I/O、代表其他线程等待和执行定时器。

 

线程池运行以下情况:

When you create a Task or Task<TResult> object to perform some task asynchronously, by default the task is scheduled to run on a thread pool thread.

您创建一个任务或任务<TResult>对象来异步执行某些任务时,默认情况下,该任务将在线程池线程上运行。

 

Asynchronous timers use the thread pool. Thread pool threads execute callbacks from the System.Threading.Timer class and raise events from the System.Timers.Timer class.

异步计时器使用线程池。线程池线程从System.Threading.Timer类执行回调,并从System.Timers.Timer类引发事件。

 

When you use registered wait handles, a system thread monitors the status of the wait handles. When a wait operation completes, a worker thread from the thread pool executes the corresponding callback function.

使用已注册的等待句柄时,系统线程将监视等待句柄的状态。当等待操作完成时,线程池中的工作线程执行相应的回调函数。

 

When you call the QueueUserWorkItem method to queue a method for execution on a thread pool thread. You do this by passing the method a WaitCallback delegate. The delegate has the signature

当您调用QueueUserWorkItem方法对线程池线程上的执行方法进行排队时。您可以通过传递方法WaitCallback委托来实现这一点。委托具有签名。

void WaitCallback(Object state)

其中状态是一个对象,它包含要由委托使用的数据。可以通过调用QueueUserWorkItem(WaitCallback,Object)方法将实际数据传递给委托。

 

注意:

The threads in the managed thread pool are background threads. That is, their IsBackground properties are true. This means that a ThreadPool thread will not keep an application running after all foreground threads have exited.

托管线程池中的线程是后台线程。也就是说,他们的IsBackplace属性是真实的。这意味着在所有前台线程退出之后,线程将不会继续运行应用程序。

 

posted on   荆棘人  阅读(235)  评论(0编辑  收藏  举报

编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
历史上的今天:
2018-09-18 asp.net应用程序脱机app_offline.htm文件

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示