GC.WaitForFullGCComplete 方法

定義

傳回註冊通知的狀態,以判斷 Common Language Runtime 是否已完成完整的封鎖記憶體回收。

多載

WaitForFullGCComplete()

傳回註冊通知的狀態,以判斷 Common Language Runtime 是否已完成完整的封鎖記憶體回收。

WaitForFullGCComplete(Int32)

在指定的逾時期間傳回註冊通知的狀態,以判斷 Common Language Runtime 是否已完成完整的封鎖記憶體回收。

WaitForFullGCComplete(TimeSpan)

傳回有關封鎖垃圾收集是否已完成的已註冊通知狀態。 可能會無限期等候完整集合。

WaitForFullGCComplete()

來源:
GC.CoreCLR.cs
來源:
GC.CoreCLR.cs
來源:
GC.CoreCLR.cs

傳回註冊通知的狀態,以判斷 Common Language Runtime 是否已完成完整的封鎖記憶體回收。

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)

來源:
GC.CoreCLR.cs
來源:
GC.CoreCLR.cs
來源:
GC.CoreCLR.cs

在指定的逾時期間傳回註冊通知的狀態,以判斷 Common Language Runtime 是否已完成完整的封鎖記憶體回收。

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)

來源:
GC.cs
來源:
GC.cs
來源:
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 通知狀態

適用於