GC.WaitForFullGCComplete 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳註冊通知狀態,用以判斷公共語言執行時是否完成了完整的阻塞性垃圾回收。
多載
| 名稱 | Description |
|---|---|
| WaitForFullGCComplete() |
回傳註冊通知狀態,用以判斷公共語言執行時是否完成了完整的阻塞性垃圾回收。 |
| WaitForFullGCComplete(Int32) |
在指定的逾時期內,回傳一個註冊通知的狀態,用以判斷執行時是否完成了一個完整的、以共同語言進行的阻塞性垃圾回收。 |
| WaitForFullGCComplete(TimeSpan) |
回傳已註冊通知狀態,告知阻塞性垃圾回收是否完成。 可能會無限期等待完整收藏。 |
WaitForFullGCComplete()
回傳註冊通知狀態,用以判斷公共語言執行時是否完成了完整的阻塞性垃圾回收。
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)
在指定的逾時期內,回傳一個註冊通知的狀態,用以判斷執行時是否完成了一個完整的、以共同語言進行的阻塞性垃圾回收。
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)
- 來源:
- GC.cs
- 來源:
- GC.cs
- 來源:
- 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
等待完整催收的暫停時間
傳回
已註冊的完整綠書通知狀態