Ler em inglês

Partilhar via


GCNotificationStatus Enumeração

Definição

Fornece informações sobre o registro atual para a notificação da próxima coleta de lixo completa.

C#
public enum GCNotificationStatus
C#
[System.Serializable]
public enum GCNotificationStatus
Herança
GCNotificationStatus
Atributos

Campos

Nome Valor Description
Canceled 2

O registro atual foi cancelado pelo usuário.

Failed 1

A notificação falhou por algum motivo.

NotApplicable 4

Esse valor pode resultar quando não há registro atual para uma notificação de coleta de lixo ou um GC completo aconteceu, mas foi feito como um GC em segundo plano (ou seja, um GC que é executado principalmente simultaneamente com threads de usuário) em vez de um GC de bloqueio completo. O GC em segundo plano está habilitado por padrão; desabilitá-la melhora a precisão da previsão, mas incorre em pausas de GC maiores.

Succeeded 0

A notificação foi bem-sucedida e o registro não foi cancelado.

Timeout 3

A hora especificada pelo parâmetro millisecondsTimeout para WaitForFullGCApproach(Int32) ou WaitForFullGCComplete(Int32) foi decorrida.

Exemplos

O exemplo a seguir obtém uma GCNotificationStatus enumeração do WaitForFullGCApproach método . Se a enumeração retornar Êxito, ela chamará o método OnFullGCApproachNotify personalizado para executar ações em resposta à coleta de lixo completa que se aproxima. Este exemplo de código faz parte de um exemplo maior fornecido para o tópico Notificações de Coleta de Lixo .

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

Comentários

Use o RegisterForFullGCNotification método para se registrar para uma notificação de coleta de lixo completa. Em seguida, use o WaitForFullGCApproach método ou o WaitForFullGCComplete método para retornar uma GCNotificationStatus enumeração que contém o status da notificação.

Aplica-se a

Produto Versões
.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

Confira também