托管线程处理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. 虽然本部分介绍的是线程基本概念,但将会重点介绍托管线程概念和如何使用托管线程。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 Threading Basics
概述了托管线程以及何时使用多线程。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 Threading Best Practices
介绍了同步级别、如何避免死锁和争用条件,以及其他线程问题。Discusses levels of synchronization, how to avoid deadlocks and race conditions, and other threading issues.

线程处理对象和功能Threading Objects and Features
介绍了可用于同步在不同线程上访问的线程活动和对象数据的托管类,并概述了线程池线程。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
收录了用于使用和同步托管线程的类。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.