<gcConcurrent > 元素<gcConcurrent> Element

指定 Common Language Runtime 是否會在個別的執行緒執行記憶體回收。Specifies whether the common language runtime runs garbage collection on a separate thread.

<configuration> <configuration>
    <runtime >   <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