GCNotificationStatus Enum
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Innehåller information om den aktuella registreringen för meddelande om nästa fullständiga skräpinsamling.
public enum class GCNotificationStatus
public enum GCNotificationStatus
[System.Serializable]
public enum GCNotificationStatus
type GCNotificationStatus =
[<System.Serializable>]
type GCNotificationStatus =
Public Enum GCNotificationStatus
- Arv
- Attribut
Fält
| Name | Värde | Description |
|---|---|---|
| Succeeded | 0 | Meddelandet lyckades och registreringen avbröts inte. |
| Failed | 1 | Meddelandet misslyckades av någon anledning. |
| Canceled | 2 | Den aktuella registreringen avbröts av användaren. |
| Timeout | 3 | Den tid som anges av parametern |
| NotApplicable | 4 | Det här värdet kan uppstå när det inte finns någon aktuell registrering för en skräpinsamlingsavisering, eller om en fullständig GC har inträffat men har gjorts som en bakgrunds-GC (dvs. en GC som främst körs samtidigt med användartrådar) i stället för en fullständig blockerande GC. Bakgrunds-GC är aktiverat som standard. inaktivering förbättrar förutsägelsenoggrannheten men medför större GC-pauser. |
Exempel
I följande exempel hämtas en GCNotificationStatus uppräkning från WaitForFullGCApproach metoden. Om uppräkningen returnerar Lyckades anropas den anpassade metoden OnFullGCApproachNotify för att utföra åtgärder som svar på den annalkande fullständiga skräpinsamlingen. Det här kodexemplet är en del av ett större exempel för avsnittet Skräpinsamlingsaviseringar .
public static void WaitForFullGCProc()
{
while (true)
{
// CheckForNotify is set to true and false in Main.
while (checkForNotify)
{
// Check for a notification of an approaching collection.
GCNotificationStatus s = GC.WaitForFullGCApproach();
if (s == GCNotificationStatus.Succeeded)
{
Console.WriteLine("GC Notification raised.");
OnFullGCApproachNotify();
}
else if (s == GCNotificationStatus.Canceled)
{
Console.WriteLine("GC Notification cancelled.");
break;
}
else
{
// This can occur if a timeout period
// is specified for WaitForFullGCApproach(Timeout)
// or WaitForFullGCComplete(Timeout)
// and the time out period has elapsed.
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;
}
}
Thread.Sleep(500);
// FinalExit is set to true right before
// the main thread cancelled notification.
if (finalExit)
{
break;
}
}
}
let waitForFullGCProc () =
let mutable broken = false
while not broken do
let mutable broken = false
// CheckForNotify is set to true and false in Main.
while checkForNotify && not broken do
// Check for a notification of an approaching collection.
match GC.WaitForFullGCApproach() with
| GCNotificationStatus.Succeeded ->
printfn "GC Notification raised."
onFullGCApproachNotify ()
// 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
| GCNotificationStatus.Canceled ->
printfn "GC Notification cancelled."
broken <- true
| _ ->
// This can occur if a timeout period
// is specified for WaitForFullGCApproach(Timeout)
// or WaitForFullGCComplete(Timeout)
// and the time out period has elapsed.
printfn "GC Notification not applicable."
broken <- true
Thread.Sleep 500
// FinalExit is set to true right before
// the main thread cancelled notification.
if finalExit then broken <- true
Public Shared Sub WaitForFullGCProc()
While True
' CheckForNotify is set to true and false in Main.
While checkForNotify
' Check for a notification of an approaching collection.
Dim s As GCNotificationStatus = GC.WaitForFullGCApproach
If (s = GCNotificationStatus.Succeeded) Then
Console.WriteLine("GC Notification raised.")
OnFullGCApproachNotify()
ElseIf (s = GCNotificationStatus.Canceled) Then
Console.WriteLine("GC Notification cancelled.")
Exit While
Else
' This can occur if a timeout period
' is specified for WaitForFullGCApproach(Timeout)
' or WaitForFullGCComplete(Timeout)
' and the time out period has elapsed.
Console.WriteLine("GC Notification not applicable.")
Exit While
End If
' 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
End While
Thread.Sleep(500)
' FinalExit is set to true right before
' the main thread cancelled notification.
If finalExit Then
Exit While
End If
End While
End Sub
Kommentarer
Använd metoden RegisterForFullGCNotification för att registrera dig för ett fullständigt skräpinsamlingsmeddelande. Använd WaitForFullGCApproach sedan metoden eller WaitForFullGCComplete metoden för att returnera en GCNotificationStatus uppräkning som innehåller status för meddelandet.