<gcConcurrent> 元素<gcConcurrent> element

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

<configuration>
  <runtime>
    <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 .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 .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 .NET Framework 4.5, background collection became available in server garbage collection. T元素控制运行时是执行并发还是后台垃圾回收(如果可用),或者是否执行前台垃圾回收。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 .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. 若要禁用后台垃圾回收,请使用t元素,如本文所述。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 t元素的属性设置为,则 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 Background garbage collection.

示例Example

下面的示例启用后台垃圾回收:The following example enables background garbage collection:

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

另请参阅See also