Lire en anglais

Partager via


GCNotificationStatus Énumération

Définition

Fournit des informations sur l’enregistrement actuel pour la notification du prochain garbage collection complet.

C#
public enum GCNotificationStatus
C#
[System.Serializable]
public enum GCNotificationStatus
Héritage
GCNotificationStatus
Attributs

Champs

Canceled 2

L’enregistrement actuel a été annulé par l'utilisateur.

Failed 1

La notification a échoué pour une raison quelconque.

NotApplicable 4

Cette valeur peut se produire lorsqu’il n’existe aucune inscription actuelle pour une notification de garbage collection, ou qu’un GC complet s’est produit, mais qu’il a été effectué en tant que GC en arrière-plan (autrement dit, un GC qui s’exécute principalement simultanément avec les threads utilisateur) au lieu d’un GC de blocage complet. Le GC en arrière-plan est activé par défaut ; la désactivation améliore la précision de prédiction, mais entraîne des pauses GC plus importantes.

Succeeded 0

La notification a réussi et l’inscription n’a pas été annulée.

Timeout 3

Le temps spécifié par le paramètre millisecondsTimeout pour WaitForFullGCApproach(Int32) ou WaitForFullGCComplete(Int32) s’est écoulé.

Exemples

L’exemple suivant obtient une GCNotificationStatus énumération à partir de la WaitForFullGCApproach méthode. Si l’énumération retourne Succeeded, elle appelle la méthode OnFullGCApproachNotify personnalisée pour effectuer des actions en réponse à l’approche du garbage collection complet. Cet exemple de code fait partie d’un exemple plus grand fourni pour la rubrique Notifications de garbage collection .

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

Remarques

Utilisez la RegisterForFullGCNotification méthode pour vous inscrire à une notification de garbage collection complète. Utilisez ensuite la WaitForFullGCApproach méthode ou la WaitForFullGCComplete méthode pour retourner une GCNotificationStatus énumération qui contient l’état de la notification.

S’applique à

Produit Versions
.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

Voir aussi