กิจกรรม
17 มี.ค. 21 - 21 มี.ค. 10
สร้างแอป AI และตัวแทน เข้าร่วมชุด meetup เพื่อสร้างโซลูชัน AI ที่ปรับขนาดได้ตามกรณีการใช้งานจริงกับนักพัฒนาและผู้เชี่ยวชาญร่วมกัน
ลงทะเบียนตอนนี้เบราว์เซอร์นี้ไม่ได้รับการสนับสนุนอีกต่อไป
อัปเกรดเป็น Microsoft Edge เพื่อใช้ประโยชน์จากคุณลักษณะล่าสุด เช่น การอัปเดตความปลอดภัยและการสนับสนุนด้านเทคนิค
The System.Threading.ThreadPool class provides your application with a pool of worker threads that are managed by the system, allowing you to concentrate on application tasks rather than thread management. If you have short tasks that require background processing, the managed thread pool is an easy way to take advantage of multiple threads. Use of the thread pool is significantly easier in Framework 4 and later, since you can create Task and Task<TResult> objects that perform asynchronous tasks on thread pool threads.
.NET uses thread pool threads for many purposes, including Task Parallel Library (TPL) operations, asynchronous I/O completion, timer callbacks, registered wait operations, asynchronous method calls using delegates, and System.Net socket connections.
Thread pool threads are background threads. Each thread uses the default stack size, runs at the default priority, and is in the multithreaded apartment. Once a thread in the thread pool completes its task, it's returned to a queue of waiting threads. From this moment it can be reused. This reuse enables applications to avoid the cost of creating a new thread for each task.
There is only one thread pool per process.
Unhandled exceptions in thread pool threads terminate the process. There are three exceptions to this rule:
For more information, see Exceptions in Managed Threads.
The number of operations that can be queued to the thread pool is limited only by available memory. However, the thread pool limits the number of threads that can be active in the process simultaneously. If all thread pool threads are busy, additional work items are queued until threads to execute them become available. The default size of the thread pool for a process depends on several factors, such as the size of the virtual address space. A process can call the ThreadPool.GetMaxThreads method to determine the number of threads.
You can control the maximum number of threads by using the ThreadPool.GetMaxThreads and ThreadPool.SetMaxThreads methods.
หมายเหตุ
Code that hosts the common language runtime can set the size using the ICorThreadpool::CorSetMaxThreads
method.
The thread pool provides new worker threads or I/O completion threads on demand until it reaches a specified minimum for each category. You can use the ThreadPool.GetMinThreads method to obtain these minimum values.
หมายเหตุ
When demand is low, the actual number of thread pool threads can fall below the minimum values.
When a minimum is reached, the thread pool can create additional threads or wait until some tasks complete. The thread pool creates and destroys worker threads in order to optimize throughput, which is defined as the number of tasks that complete per unit of time. Too few threads might not make optimal use of available resources, whereas too many threads could increase resource contention.
ข้อควรระวัง
You can use the ThreadPool.SetMinThreads method to increase the minimum number of idle threads. However, unnecessarily increasing these values can cause performance problems. If too many tasks start at the same time, all of them might appear to be slow. In most cases the thread pool will perform better with its own algorithm for allocating threads.
The easiest way to use the thread pool is to use the Task Parallel Library (TPL). By default, TPL types like Task and Task<TResult> use thread pool threads to run tasks.
You can also use the thread pool by calling ThreadPool.QueueUserWorkItem from managed code (or ICorThreadpool::CorQueueUserWorkItem
from unmanaged code) and passing a System.Threading.WaitCallback delegate representing the method that performs the task.
Another way to use the thread pool is to queue work items that are related to a wait operation by using the ThreadPool.RegisterWaitForSingleObject method and passing a System.Threading.WaitHandle that, when signaled or when timed out, calls the method represented by the System.Threading.WaitOrTimerCallback delegate. Thread pool threads are used to invoke callback methods.
For the examples, check the referenced API pages.
The thread pool also provides the ThreadPool.UnsafeQueueUserWorkItem and ThreadPool.UnsafeRegisterWaitForSingleObject methods. Use these methods only when you are certain that the caller's stack is irrelevant to any security checks performed during the execution of the queued task. ThreadPool.QueueUserWorkItem and ThreadPool.RegisterWaitForSingleObject both capture the caller's stack, which is merged into the stack of the thread pool thread when the thread begins to execute a task. If a security check is required, the entire stack must be checked. Although the check provides safety, it also has a performance cost.
There are several scenarios in which it's appropriate to create and manage your own threads instead of using thread pool threads:
คำติชม .NET
.NET เป็นโครงการโอเพนซอร์ส เลือกลิงก์เพื่อให้คำติชม:
กิจกรรม
17 มี.ค. 21 - 21 มี.ค. 10
สร้างแอป AI และตัวแทน เข้าร่วมชุด meetup เพื่อสร้างโซลูชัน AI ที่ปรับขนาดได้ตามกรณีการใช้งานจริงกับนักพัฒนาและผู้เชี่ยวชาญร่วมกัน
ลงทะเบียนตอนนี้การฝึกอบรม
เส้นทางการเรียนรู้
Azure에서 HPC(고성능 컴퓨팅) 애플리케이션 실행 - Training
Azure HPC는 최고의 애플리케이션 성능, 스케일링 기능 및 가치를 제공하기 위해 최첨단 프로세서와 HPC급 InfiniBand 상호 연결을 사용하는 HPC 및 AI 워크로드용으로 특화된 클라우드 기능입니다. 사용자는 Azure HPC를 사용하여 비즈니스 및 기술 요구 사항이 달라질 때 동적으로 할당될 수 있는 고가용성의 HPC 및 AI 기술을 통해 뛰어난 혁신, 생산성 및 비즈니스 민첩성을 얻을 수 있습니다. 이 학습 경로는 Azure HPC에서 시작하는 데 도움이 되는 모듈 시리즈입니다. 가장 관심 있는 토픽을 선택하거나 하나씩 진행할 수 있습니다.