Managed 執行緒處理Managed Threading

不論您開發的是搭載一或多個處理器的電腦,即使應用程式目前正在執行其他工作,您還是希望應用程式能以最快速度與使用者互動。Whether you are developing for computers with one processor or several, you want your application to provide the most responsive interaction with the user, even if the application is currently doing other work. 使用多執行緒的執行是一種讓應用程式能迅速回應使用者,同時能夠在使用者事件之間或甚至在使用者事件當中善用處理器的強大方法。Using multiple threads of execution is one of the most powerful ways to keep your application responsive to the user and at the same time make use of the processor in between or even during user events. 雖然本節將介紹執行緒處理的基本概念,但是重點會放在 Managed 執行緒處理概念和如何使用 Managed 執行緒處理。While this section introduces the basic concepts of threading, it focuses on managed threading concepts and using managed threading.

注意

從 .NET Framework 4 開始,多執行緒的程式設計已透過 System.Threading.Tasks.ParallelSystem.Threading.Tasks.Task 類別、平行 LINQ (PLINQ)System.Collections.Concurrent 命名空間中的新並行集合類別,以及以工作 (而非執行緒) 概念為基礎的新程式設計模型,而做出大幅簡化。Starting with the .NET Framework 4, multithreaded programming is greatly simplified with the System.Threading.Tasks.Parallel and System.Threading.Tasks.Task classes, Parallel LINQ (PLINQ), new concurrent collection classes in the System.Collections.Concurrent namespace, and a new programming model that is based on the concept of tasks rather than threads. 如需詳細資訊,請參閱平行程式設計For more information, see Parallel Programming.

本節內容In This Section

Managed 執行緒處理的基本概念Managed Threading Basics
提供 Managed 執行緒處理的概觀,並討論何時使用多個執行緒。Provides an overview of managed threading and discusses when to use multiple threads.

使用執行緒和執行緒處理Using Threads and Threading
說明如何建立、啟動、暫停、繼續和中止執行緒。Explains how to create, start, pause, resume, and abort threads.

Managed 執行緒處理的最佳實施方針Managed Threading Best Practices
討論同步處理的層級、如何避免死結和競爭條件,以及其他執行緒處理問題。Discusses levels of synchronization, how to avoid deadlocks and race conditions, and other threading issues.

執行緒物件和功能Threading Objects and Features
描述可用來同步執行緒活動的 Managed 類別,以及在不同執行緒上存取的物件資料,並提供執行緒集區執行緒的概觀。Describes the managed classes you can use to synchronize the activities of threads and the data of objects accessed on different threads, and provides an overview of thread pool threads.

參考資料Reference

System.Threading
包含使用和同步 Managed 執行緒的類別。Contains classes for using and synchronizing managed threads.

System.Collections.Concurrent
包含可安全用於多個執行緒的集合類別。Contains collection classes that are safe for use with multiple threads.

System.Threading.Tasks
包含建立和排程並行處理工作的類別。Contains classes for creating and scheduling concurrent processing tasks.

應用程式定義域Application Domains
提供應用程式定義域的概觀及通用語言基礎結構如何使用它們。Provides an overview of application domains and their use by the Common Language Infrastructure.

Asynchronous File I/OAsynchronous File I/O
描述非同步 I/O 的效能利益和基本作業。Describes the performance advantages and basic operation of asynchronous I/O.

工作式非同步模式 (TAP)Task-based Asynchronous Pattern (TAP)
提供 .NET 中非同步程式設計建議模式的概觀。Provides an overview of the recommended pattern for asynchronous programming in .NET.

非同步呼叫同步方法Calling Synchronous Methods Asynchronously
說明如何使用內建的委派功能在執行緒集區執行緒上呼叫方法。Explains how to call methods on thread pool threads using built-in features of delegates.

平行程式設計Parallel Programming
描述平行程式設計程式庫,簡化應用程式中多個執行緒的用法。Describes the parallel programming libraries, which simplify the use of multiple threads in applications.

平行 LINQ (PLINQ)Parallel LINQ (PLINQ)
描述以平行方式執行查詢的系統,以善用多個處理器。Describes a system for running queries in parallel, to take advantage of multiple processors.