GCSettings.IsServerGC GCSettings.IsServerGC GCSettings.IsServerGC GCSettings.IsServerGC Property

定义

获取一个值,该值指示是否启用了服务器垃圾回收。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>  

适用于