Leer en inglés

Compartir a través de


GCNotificationStatus Enumeración

Definición

Proporciona información sobre el registro actual para la notificación de la siguiente recolección completa de elementos no utilizados.

C#
public enum GCNotificationStatus
C#
[System.Serializable]
public enum GCNotificationStatus
Herencia
GCNotificationStatus
Atributos

Campos

Nombre Valor Description
Canceled 2

El usuario canceló el registro actual.

Failed 1

Error en la notificación por algún motivo.

NotApplicable 4

Este valor puede dar lugar cuando no hay ningún registro actual para una notificación de recolección de elementos no utilizados, o se ha producido un GC completo, pero se ha realizado como gc en segundo plano (es decir, un GC que se ejecuta principalmente simultáneamente con subprocesos de usuario) en lugar de un GC de bloqueo completo. Gc en segundo plano está habilitado de forma predeterminada; deshabilitarla mejora la precisión de la predicción, pero incurre en pausas de GC más grandes.

Succeeded 0

La notificación se realizó correctamente y no se canceló el registro.

Timeout 3

La hora especificada por el parámetro millisecondsTimeout para WaitForFullGCApproach(Int32) o WaitForFullGCComplete(Int32) ha transcurrido.

Ejemplos

En el ejemplo siguiente se obtiene una GCNotificationStatus enumeración del WaitForFullGCApproach método . Si la enumeración devuelve Succeeded, llama al método OnFullGCApproachNotify personalizado para realizar acciones en respuesta a la recolección completa de elementos no utilizados. Este ejemplo de código forma parte de un ejemplo más grande proporcionado para el tema Notificaciones de recolección de elementos no utilizados.

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

Comentarios

Use el RegisterForFullGCNotification método para registrarse para una notificación completa de recolección de elementos no utilizados. A continuación, use el WaitForFullGCApproach método o el WaitForFullGCComplete método para devolver una GCNotificationStatus enumeración que contiene el estado de la notificación.

Se aplica a

Producto Versiones
.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

Consulte también