GCSettings.IsServerGC 屬性

定義

取得值,這個值表示伺服器記憶體回收是否已啟用。

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

屬性值

如果伺服器記憶體回收已啟用,則為 true,否則為 false

範例

下列範例指出主機電腦是否使用伺服器或工作站垃圾收集。

using System;
using System.Runtime;

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

        if (GCSettings.IsServerGC)
            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.

備註

如需伺服器垃圾收集的相關資訊,請參閱 工作站和伺服器垃圾收集

如果未啟用伺服器垃圾收集,工作站垃圾收集就會生效, (或沒有並行收集) 。 伺服器垃圾收集僅適用于多處理器電腦上。

非受控主機可以要求伺服器垃圾收集,而主機要求會覆寫組態檔設定。 如果主機未指定垃圾收集的類型,您可以使用組態設定來指定伺服器垃圾收集。 如需詳細資訊,請參閱 設定工作站與伺服器

適用於