<gcConcurrent > 元素<gcConcurrent> element

指定 Common Language Runtime 是否會在個別的執行緒執行記憶體回收。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 .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. 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 .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. 如果您將gcConcurrent元素的 enabled 屬性設定為 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, Background workstation garbage collection, and Background server garbage collection sections in the Fundamentals of Garbage Collection article.

範例Example

下列範例會啟用背景垃圾收集:The following example enables background garbage collection:

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

請參閱See also