语言

GC.WaitForFullGCComplete 方法

定义

返回已注册通知的状态,用于确定是否已完成公共语言运行时的完整阻止垃圾回收。

重载

名称 说明
WaitForFullGCComplete()

返回已注册通知的状态,用于确定是否已完成公共语言运行时的完整阻止垃圾回收。

WaitForFullGCComplete(Int32)

返回在指定的超时时间段内,注册通知的状态,用于确定运行时已完成的公共语言是否完全阻止垃圾回收。

WaitForFullGCComplete(TimeSpan)

返回有关阻止垃圾回收是否已完成的已注册通知的状态。 可以无限期等待完整集合。

WaitForFullGCComplete()

Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs

返回已注册通知的状态,用于确定是否已完成公共语言运行时的完整阻止垃圾回收。

public:
 static GCNotificationStatus WaitForFullGCComplete();
public static GCNotificationStatus WaitForFullGCComplete();
[System.Security.SecurityCritical]
public static GCNotificationStatus WaitForFullGCComplete();
static member WaitForFullGCComplete : unit -> GCNotificationStatus
[<System.Security.SecurityCritical>]
static member WaitForFullGCComplete : unit -> GCNotificationStatus
Public Shared Function WaitForFullGCComplete () As GCNotificationStatus

返回

已注册垃圾回收通知的状态。

特性

示例

下面的示例演示如何使用此方法来确定完全垃圾回收是否已完成。 每当通知的状态为 Succeeded时,将调用用户方法 OnFullGCCompletedNotify 以执行操作以响应已完成的集合。 此代码示例是针对 垃圾回收通知 主题提供的较大示例的一部分。

// Check for a notification of a completed collection.
GCNotificationStatus status = GC.WaitForFullGCComplete();
if (status == GCNotificationStatus.Succeeded)
{
    Console.WriteLine("GC Notification raised.");
    OnFullGCCompleteEndNotify();
}
else if (status == GCNotificationStatus.Canceled)
{
    Console.WriteLine("GC Notification cancelled.");
    break;
}
else
{
    // Could be a time out.
    Console.WriteLine("GC Notification not applicable.");
    break;
}
// Check for a notification of a completed collection.
match GC.WaitForFullGCComplete() with
| GCNotificationStatus.Succeeded ->
    printfn "GC Notification raised."
    onFullGCCompleteEndNotify ()
| GCNotificationStatus.Canceled ->
    printfn "GC Notification cancelled."
    broken <- true
| _ ->
    // Could be a time out.
    printfn "GC Notification not applicable."
    broken <- true
' Check for a notification of a completed collection.
s = GC.WaitForFullGCComplete
If (s = GCNotificationStatus.Succeeded) Then
    Console.WriteLine("GC Notifiction raised.")
    OnFullGCCompleteEndNotify()
ElseIf (s = GCNotificationStatus.Canceled) Then
    Console.WriteLine("GC Notification cancelled.")
    Exit While
Else
    ' Could be a time out.
    Console.WriteLine("GC Notification not applicable.")
    Exit While
End If

注解

使用此方法返回的 GCNotificationStatus 枚举来确定使用 RegisterForFullGCNotification 该方法注册的当前垃圾回收通知的状态。 还可以使用该方法 WaitForFullGCApproach 来确定完全垃圾回收是否迫在眉睫。

枚举返回 Succeeded时,可以使用该方法执行恢复工作和获取集合计数 CollectionCount(Int32) 等任务。

此方法无限期等待获取垃圾回收通知。 如果要为方法指定超时期限,以便在无法获取通知时返回,请使用方法 GC.WaitForFullGCApproach(Int32) 重载。 如果在未指定超时的情况下调用此方法,则可以在等待时间超过首选时间时调用该方法 CancelFullGCNotification 。

此方法调用应前面有对方法的调用 WaitForFullGCApproach ,以确保已进行完全垃圾回收。 单独调用此方法可能会生成不确定的结果。

另请参阅

适用于

WaitForFullGCComplete(Int32)

Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs

返回在指定的超时时间段内,注册通知的状态,用于确定运行时已完成的公共语言是否完全阻止垃圾回收。

public:
 static GCNotificationStatus WaitForFullGCComplete(int millisecondsTimeout);
public static GCNotificationStatus WaitForFullGCComplete(int millisecondsTimeout);
[System.Security.SecurityCritical]
public static GCNotificationStatus WaitForFullGCComplete(int millisecondsTimeout);
static member WaitForFullGCComplete : int -> GCNotificationStatus
[<System.Security.SecurityCritical>]
static member WaitForFullGCComplete : int -> GCNotificationStatus
Public Shared Function WaitForFullGCComplete (millisecondsTimeout As Integer) As GCNotificationStatus

参数

millisecondsTimeout
Int32

获取通知状态之前等待的时间长度。 指定 -1 无限期等待。

返回

已注册垃圾回收通知的状态。

特性

例外

millisecondsTimeout 必须为非负值或小于或等于 Int32.MaxValue 或 -1。

注解

使用此方法返回的 GCNotificationStatus 枚举来确定使用 RegisterForFullGCNotification 该方法注册的当前垃圾回收通知的状态。 还可以使用该方法 WaitForFullGCApproach 来确定完全垃圾回收是否迫在眉睫。

请注意,无论指定的 millisecondsTimeout值如何,此方法都会在获取垃圾回收通知状态时立即返回。 如果在超时前 millisecondsTimeout 未获取垃圾回收通知状态,此方法将 NotApplicable返回。

枚举返回 Succeeded时,可以执行恢复工作和获取具有属性的集合计数 CollectionCount(Int32) 等任务。

当无法等待超时期限过时,可以调用 CancelFullGCNotification 该方法。

此方法调用应前面有对方法的调用 WaitForFullGCApproach ,以确保已进行完全垃圾回收。 单独调用此方法可能会生成不确定的结果。

另请参阅

适用于

WaitForFullGCComplete(TimeSpan)

Source:
GC.cs
Source:
GC.cs
Source:
GC.cs
Source:
GC.cs
Source:
GC.cs

返回有关阻止垃圾回收是否已完成的已注册通知的状态。 可以无限期等待完整集合。

public:
 static GCNotificationStatus WaitForFullGCComplete(TimeSpan timeout);
public static GCNotificationStatus WaitForFullGCComplete(TimeSpan timeout);
static member WaitForFullGCComplete : TimeSpan -> GCNotificationStatus
Public Shared Function WaitForFullGCComplete (timeout As TimeSpan) As GCNotificationStatus

参数

timeout
TimeSpan

等待完整集合的超时

返回

已注册的完整 GC 通知的状态

适用于