Leggere in inglese

Condividi tramite


GCNotificationStatus Enumerazione

Definizione

Fornisce informazioni sulla registrazione corrente per la notifica della successiva Garbage Collection completa.

C#
public enum GCNotificationStatus
C#
[System.Serializable]
public enum GCNotificationStatus
Ereditarietà
GCNotificationStatus
Attributi

Campi

Nome Valore Descrizione
Canceled 2

La registrazione corrente è stata annullata dall'utente.

Failed 1

La notifica non è riuscita per un motivo qualsiasi.

NotApplicable 4

Questo valore può risultare quando non è presente alcuna registrazione corrente per una notifica di Garbage Collection o è stato eseguito un GC completo, ma è stato eseguito come GC in background, ovvero un GC che viene eseguito principalmente contemporaneamente ai thread utente, anziché un GC di blocco completo. La GC in background è abilitata per impostazione predefinita; disabilitando migliora l'accuratezza della stima, ma comporta pause GC più grandi.

Succeeded 0

La notifica è riuscita e la registrazione non è stata annullata.

Timeout 3

Il tempo specificato dal parametro millisecondsTimeout per WaitForFullGCApproach(Int32) o WaitForFullGCComplete(Int32) è trascorso.

Esempio

Nell'esempio seguente viene ottenuta un'enumerazione GCNotificationStatusWaitForFullGCApproach dal metodo . Se l'enumerazione restituisce Successed, chiama il metodo OnFullGCApproachNotify personalizzato per eseguire azioni in risposta all'approccio di Garbage Collection completo. Questo esempio di codice fa parte di un esempio più ampio fornito per l'argomento Notifiche di 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;
        }
    }
}

Commenti

Usare il metodo per eseguire la RegisterForFullGCNotification registrazione per una notifica di Garbage Collection completa. Usare quindi il metodo o il WaitForFullGCApproachWaitForFullGCComplete metodo per restituire un'enumerazione GCNotificationStatus contenente lo stato della notifica.

Si applica a

Prodotto Versioni
.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

Vedi anche