GCNotificationStatus Enum

Definitie

Bevat informatie over de huidige registratie voor de melding van de volgende volledige garbagecollection.

public enum class GCNotificationStatus
[System.Serializable]
public enum GCNotificationStatus
public enum GCNotificationStatus
[<System.Serializable>]
type GCNotificationStatus = 
type GCNotificationStatus = 
Public Enum GCNotificationStatus
Overname
GCNotificationStatus
Kenmerken

Velden

Name Waarde Description
Succeeded 0

De melding is geslaagd en de registratie is niet geannuleerd.

Failed 1

De melding is om welke reden dan ook mislukt.

Canceled 2

De huidige registratie is geannuleerd door de gebruiker.

Timeout 3

De tijd die is opgegeven door de millisecondsTimeout parameter voor WaitForFullGCApproach(Int32) of WaitForFullGCComplete(Int32) is verstreken.

NotApplicable 4

Deze waarde kan ertoe leiden dat er geen huidige registratie is voor een garbagecollectionmelding, of dat er een volledige GC is gebeurd, maar is uitgevoerd als achtergrond-GC (een GC die voornamelijk gelijktijdig met gebruikersthreads wordt uitgevoerd) in plaats van een volledige blokkerende GC. Achtergrond GC is standaard ingeschakeld; als u deze functie uitschakelt, wordt de nauwkeurigheid van de voorspelling verbeterd, maar worden er grotere GC-pauzes onderbroken.

Voorbeelden

In het volgende voorbeeld wordt een GCNotificationStatus opsomming opgehaald uit de WaitForFullGCApproach methode. Als de opsomming Geslaagd retourneert, wordt de aangepaste methode OnFullGCApproachNotify aangeroepen om acties uit te voeren als reactie op de volledige garbagecollection. Dit codevoorbeeld maakt deel uit van een groter voorbeeld voor het onderwerp Garbagecollection-meldingen .

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

Opmerkingen

Gebruik de RegisterForFullGCNotification methode om u te registreren voor een volledige garbagecollectionmelding. Gebruik vervolgens de WaitForFullGCApproach methode of de WaitForFullGCComplete methode om een GCNotificationStatus opsomming te retourneren die de status van de melding bevat.

Van toepassing op

Zie ook