<t > 元素<gcConcurrent> Element

指定公共语言运行时是否在单独线程上运行垃圾回收。Specifies whether the common language runtime runs garbage collection on a separate thread.

<configuration> <configuration>
   <运行时 >   <runtime>
     <gcConcurrent>    <gcConcurrent>

语法Syntax

<gcConcurrent
   enabled="true|false"/>

特性和元素Attributes and elements

下列各节描述了特性、子元素和父元素。The following sections describe attributes, child elements, and parent elements.

特性Attributes

特性Attribute 描述Description
enabled 必需的特性。Required attribute.

指定运行时是否并发运行服务器垃圾回收。Specifies whether the runtime runs garbage collection concurrently.

enabled 属性enabled attribute

Value 描述Description
false 不并发运行垃圾回收。Doesn't run garbage collection concurrently.
true 并发运行垃圾回收。Runs garbage collection concurrently. 这是默认设置。This is the default.

子元素Child elements

无。None.

父元素Parent elements

元素Element 描述Description
configuration 公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中的根元素。The root element in every configuration file used by the common language runtime and .NET Framework applications.
runtime 包含有关程序集绑定和垃圾回收的信息。Contains information about assembly binding and garbage collection.

备注Remarks

在.NET Framework 4 之前,工作站垃圾回收支持并发垃圾回收,在后台对一个单独线程执行垃圾回收。Prior to the .NET Framework 4, workstation garbage collection supported concurrent garbage collection, which performed garbage collection in the background on a separate thread. 在.NET Framework 4 中,并发垃圾回收被后台 GC 取代,它还在单独的线程上在后台中执行垃圾回收。In the .NET Framework 4, concurrent garbage collection was replaced by background GC, which also performs garbage collection in the background on a separate thread. 从 .NET Framework 4.5 开始,服务器垃圾回收可提供后台垃圾回收。Starting with the .NET Framework 4.5, background collection became available in server garbage collection. <gcConcurrent>元素控制运行时是执行并发还是后台垃圾回收(如果可用),或者是否执行前台垃圾回收。The <gcConcurrent> element controls whether the runtime performs either concurrent or background garbage collection, if it's available, or whether it performs garbage collection in the foreground.

禁用后台垃圾回收To disable background garbage collection

警告

从.NET Framework 4 开始,并发垃圾回收替换为后台垃圾回收。Starting with the .NET Framework 4, concurrent garbage collection is replaced by background garbage collection. 在 .NET Framework 文档中,术语 "并发" 和 "背景" 可互换使用。The terms concurrent and background are used interchangeably in the .NET Framework documentation. 若要禁用后台垃圾回收,请使用 <gcConcurrent> 元素,如本文所述。To disable background garbage collection, use the <gcConcurrent> element, as discussed in this article.

默认情况下,运行时使用并发或后台垃圾回收,回收针对延迟进行了优化。By default, the runtime uses concurrent or background garbage collection, which is optimized for latency. 如果应用程序涉及大量用户交互,则通过让并发垃圾回收保持启用状态,可最大限度缩短应用程序执行垃圾回收时的暂停时间。If your application involves heavy user interaction, leave concurrent garbage collection enabled to minimize the application's pause time to perform garbage collection. 如果将 enabled 元素的 <gcConcurrent> 特性设置为 false,运行时将使用针对吞吐量优化的非并发垃圾回收。If you set the enabled attribute of the <gcConcurrent> element to false, the runtime uses non-concurrent garbage collection, which is optimized for throughput. 下列配置文件会禁用后台垃圾回收。The following configuration file disables background garbage collection.

<configuration>
   <runtime>
      <gcConcurrent enabled="false"/>
   </runtime>
</configuration>

如果计算机配置文件<gcConcurrentSetting>中存在一个设置,则会为所有 .NET Framework 应用程序定义默认值。If there's a <gcConcurrentSetting> setting in the machine configuration file, it defines the default value for all .NET Framework applications. 计算机配置文件设置将重写应用程序配置文件设置。The machine configuration file setting overrides the application configuration file setting.

有关并发和后台垃圾回收的详细信息,请参阅垃圾回收基础知识一文中的 "并发垃圾回收" 一节。For more information on concurrent and background garbage collection, see the Concurrent garbage collection section in the Fundamentals of Garbage Collection article.

示例Example

下面的示例启用并发垃圾回收:The following example enables concurrent garbage collection:

<configuration>
   <runtime>
      <gcConcurrent enabled="true"/>
   </runtime>
</configuration>

请参阅See also