Auf Englisch lesen

Freigeben über


GCNotificationStatus Enumeration

Definition

Bietet Informationen über die aktuelle Registrierung für eine Benachrichtigung über die nächste vollständige Garbage Collection.

C#
public enum GCNotificationStatus
C#
[System.Serializable]
public enum GCNotificationStatus
Vererbung
GCNotificationStatus
Attribute

Felder

Name Wert Beschreibung
Canceled 2

Die aktuelle Registrierung wurde vom Benutzer abgebrochen.

Failed 1

Fehler bei der Benachrichtigung aus beliebigem Grund.

NotApplicable 4

Dieser Wert kann auftreten, wenn keine aktuelle Registrierung für eine Garbage Collection-Benachrichtigung vorhanden ist oder eine vollständige GC stattgefunden hat, die jedoch als Hintergrund-GC (d. h. eine GC, die größtenteils gleichzeitig mit Benutzerthreads ausgeführt wird) anstelle einer vollständig blockierenden GC durchgeführt wurde. Hintergrund-GC ist standardmäßig aktiviert. Die Deaktivierung verbessert die Vorhersagegenauigkeit, es entstehen jedoch größere GC-Pausen.

Succeeded 0

Die Benachrichtigung war erfolgreich, und die Registrierung wurde nicht abgebrochen.

Timeout 3

Die vom millisecondsTimeout-Parameter entweder für WaitForFullGCApproach(Int32) oder WaitForFullGCComplete(Int32) angegebene Zeit ist verstrichen.

Beispiele

Im folgenden Beispiel wird eine GCNotificationStatus Enumeration von der WaitForFullGCApproach -Methode abgerufen. Wenn die Enumeration Erfolgreich zurückgibt, ruft sie die benutzerdefinierte Methode OnFullGCApproachNotify auf, um Aktionen als Reaktion auf die sich nähernde vollständige Garbage Collection auszuführen. Dieses Codebeispiel ist Teil eines größeren Beispiels für Garbage Collection-Benachrichtigungen .

C#
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;
        }
    }
}

Hinweise

Verwenden Sie die RegisterForFullGCNotification -Methode, um sich für eine vollständige Garbage Collection-Benachrichtigung zu registrieren. Verwenden Sie dann die WaitForFullGCApproach -Methode oder - WaitForFullGCComplete Methode, um eine GCNotificationStatus Enumeration zurückzugeben, die den Status der Benachrichtigung enthält.

Gilt für:

Produkt Versionen
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1

Weitere Informationen