GCSettings.IsServerGC 屬性

定義

取得值,這個值表示伺服器記憶體回收是否已啟用。Gets a value that indicates whether server garbage collection is enabled.

public:
 static property bool IsServerGC { bool get(); };
public static bool IsServerGC { get; }
member this.IsServerGC : bool
Public Shared ReadOnly Property IsServerGC As Boolean

屬性值

如果伺服器記憶體回收已啟用,則為 true,否則為 falsetrue if server garbage collection is enabled; otherwise, false.

範例

下列範例會指出主機電腦使用的是伺服器或工作站垃圾收集。The following example indicates whether the host computer is using server or workstation garbage collection.

using System;
using System.Runtime;

class Sample
{
    public static void Main()
    {
        string result;

        if (GCSettings.IsServerGC == true)
            result = "server";
        else
            result = "workstation";
        Console.WriteLine("The {0} garbage collector is running.", result);
    }
}
// The example displays output like the following:
//      The workstation garbage collector is running.
Imports System.Runtime

Class Sample
   Public Shared Sub Main()
      Dim result As String
      
      If GCSettings.IsServerGC = True Then
         result = "server"
      Else
         result = "workstation"
      End If
      Console.WriteLine("The {0} garbage collector is running.", result)
   End Sub
End Class 
' The example displays output like the following:
'      The workstation garbage collector is running.

備註

如需伺服器垃圾收集的詳細資訊,請參閱垃圾收集的基本概念中的「工作站和伺服器垃圾收集」一節。For information about server garbage collection, see the "Workstation and Server Garbage Collection" section in Fundamentals of Garbage Collection.

如果未啟用伺服器垃圾收集,則工作站垃圾收集會生效(不論是否有並行集合)。If server garbage collection is not enabled, workstation garbage collection is in effect (with or without concurrent collection). 伺服器垃圾收集僅適用于多處理器電腦。Server garbage collection is available only on multiprocessor computers.

非受控主機可以要求伺服器垃圾收集,而主機要求會覆寫設定檔案設定。An unmanaged host can request server garbage collection, and the host request overrides configuration file settings. 如果主機未指定垃圾收集的類型,您可以使用設定檔設定來指定伺服器垃圾收集。If the host does not specify the type of garbage collection, you can use a configuration file setting to specify server garbage collection. 此設定只在應用程式佈建檔中有效,而不是在電腦設定檔中(請參閱設定應用程式)。This setting is valid only in the application configuration file, not in the machine configuration file (see Configuring Apps). 下列範例顯示可啟用伺服器垃圾收集的範例應用程式佈建檔內容。The following example shows the contents of a sample application configuration file that enables server garbage collection.

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

適用於