GCNotificationStatus Výčet

Definice

Poskytuje informace o aktuální registraci pro oznámení o dalším úplném uvolňování paměti.

public enum class GCNotificationStatus
public enum GCNotificationStatus
[System.Serializable]
public enum GCNotificationStatus
type GCNotificationStatus = 
[<System.Serializable>]
type GCNotificationStatus = 
Public Enum GCNotificationStatus
Dědičnost
GCNotificationStatus
Atributy

Pole

Canceled 2

Aktuální registrace byla zrušena uživatelem.

Failed 1

Oznámení se z jakéhokoli důvodu nezdařilo.

NotApplicable 4

Tato hodnota může vést k tomu, že neexistuje žádná aktuální registrace oznámení o uvolňování paměti nebo došlo k úplnému blokování GC, ale bylo provedeno jako GC na pozadí (tj. GC, který běží převážně souběžně s uživatelskými vlákny) místo úplného blokování GC. Služba GC na pozadí je ve výchozím nastavení povolená; tím se zvyšuje přesnost předpovědi, ale způsobuje větší pozastavení GC.

Succeeded 0

Oznámení bylo úspěšné a registrace nebyla zrušena.

Timeout 3

Doba zadaná parametrem millisecondsTimeout nebo WaitForFullGCApproach(Int32) WaitForFullGCComplete(Int32) uplynula.

Příklady

Následující příklad získá GCNotificationStatus výčet z WaitForFullGCApproach metody. Pokud výčet vrátí úspěch, zavolá vlastní metodu OnFullGCApproachNotify , která provede akce v reakci na přístup k úplnému uvolňování paměti. Tento příklad kódu je součástí většího příkladu určeného pro téma Oznámení o uvolňování paměti .

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 Notifiction 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.
                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;
                }
            }


            Thread::Sleep(500);
            // FinalExit is set to true right before
            // the main thread cancelled notification.
            if (finalExit)
            {
                break;
            }
        }
    }
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

Poznámky

RegisterForFullGCNotification Pomocí metody zaregistrujte úplné oznámení o uvolňování paměti. Pak použijte metodu WaitForFullGCApproach nebo metodu WaitForFullGCComplete GCNotificationStatus k vrácení výčtu, který obsahuje stav oznámení.

Platí pro

Viz také