GC.WaitForFullGCComplete 方法

定义

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

重载

WaitForFullGCComplete()

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

WaitForFullGCComplete(Int32)

在指定的超时期限内,返回已注册通知的状态,用于确定公共语言运行时引发的完整、阻碍性垃圾回收是否已完成。

WaitForFullGCComplete(TimeSpan)

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

WaitForFullGCComplete()

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时,将调用 user 方法 OnFullGCCompletedNotify 以执行操作以响应已完成的集合。 此代码示例是针对 垃圾回收通知 主题提供的更大示例的一部分。

// Check for a notification of a completed collection.
s = GC::WaitForFullGCComplete();
if (s == GCNotificationStatus::Succeeded)
{
    Console::WriteLine("GC Notification raised.");
    OnFullGCCompleteEndNotify();
}
else if (s == 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.
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 之类的任务。

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

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

另请参阅

适用于

WaitForFullGCComplete(Int32)

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 之类的任务。

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

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

另请参阅

适用于

WaitForFullGCComplete(TimeSpan)

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 通知的状态

适用于