다음을 통해 공유


GCNotificationStatus 열거형

정의

다음 전체 가비지 수집에 대한 알림에 현재 등록에 대한 정보를 제공합니다.

public enum class GCNotificationStatus
public enum GCNotificationStatus
[System.Serializable]
public enum GCNotificationStatus
type GCNotificationStatus = 
[<System.Serializable>]
type GCNotificationStatus = 
Public Enum GCNotificationStatus
상속
GCNotificationStatus
특성

필드

Canceled 2

사용자가 현재 등록을 취소했습니다.

Failed 1

어떤 이유로든 알림이 실패했습니다.

NotApplicable 4

이 값은 가비지 수집 알림에 대한 현재 등록이 없거나 전체 GC가 발생했지만 전체 차단 GC 대신 백그라운드 GC(즉, 주로 사용자 스레드와 동시에 실행되는 GC)로 수행된 경우 발생할 수 있습니다. 백그라운드 GC는 기본적으로 사용하도록 설정됩니다. 사용하지 않도록 설정하면 예측 정확도가 향상되지만 더 큰 GC 일시 중지가 발생합니다.

Succeeded 0

알림이 성공적으로 수행되었으며 등록이 취소되지 않았습니다.

Timeout 3

WaitForFullGCApproach(Int32) 또는 WaitForFullGCComplete(Int32)에 대해 millisecondsTimeout 매개 변수로 지정된 시간이 경과되었습니다.

예제

다음 예제에서는 GCNotificationStatus 메서드에서 열거형을 WaitForFullGCApproach 가져옵니다. 열거형이 Succeeded를 반환하는 경우 사용자 지정 메서드 OnFullGCApproachNotify 를 호출하여 접근 중인 전체 가비지 수집에 대한 응답으로 작업을 수행합니다. 이 코드 예제는 가비지 수집 알림 항목에 제공된 더 큰 예제의 일부입니다.

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 Notifiction 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.
                s = GC::WaitForFullGCComplete();
                if (s == GCNotificationStatus::Succeeded)
                {
                    Console::WriteLine("GC Notification raised.");
                    OnFullGCCompleteEndNotify();
                }
                else if (s == 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;
            }
        }
    }
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;
        }
    }
}
let waitForFullGCProc () =
    let mutable broken = false

    while not broken do
        let mutable broken = false
        // CheckForNotify is set to true and false in Main.
        while checkForNotify && not broken do
            // Check for a notification of an approaching collection.
            match GC.WaitForFullGCApproach() with
            | GCNotificationStatus.Succeeded ->
                printfn "GC Notification raised."
                onFullGCApproachNotify ()
                // Check for a notification of a completed collection.
                match GC.WaitForFullGCComplete() with
                | GCNotificationStatus.Succeeded ->
                    printfn "GC Notification raised."
                    onFullGCCompleteEndNotify ()
                | GCNotificationStatus.Canceled ->
                    printfn "GC Notification cancelled."
                    broken <- true
                | _ ->
                    // Could be a time out.
                    printfn "GC Notification not applicable."
                    broken <- true
            | GCNotificationStatus.Canceled ->
                printfn "GC Notification cancelled."
                broken <- true
            | _ ->
                // This can occur if a timeout period
                // is specified for WaitForFullGCApproach(Timeout)
                // or WaitForFullGCComplete(Timeout)
                // and the time out period has elapsed.
                printfn "GC Notification not applicable."
                broken <- true

        Thread.Sleep 500
        // FinalExit is set to true right before
        // the main thread cancelled notification.
        if finalExit then broken <- true
Public Shared Sub WaitForFullGCProc()

    While True
        ' CheckForNotify is set to true and false in Main.

        While checkForNotify
            ' Check for a notification of an approaching collection.
            Dim s As GCNotificationStatus = GC.WaitForFullGCApproach
            If (s = GCNotificationStatus.Succeeded) Then
                Console.WriteLine("GC Notification raised.")
                OnFullGCApproachNotify()
            ElseIf (s = GCNotificationStatus.Canceled) Then
                Console.WriteLine("GC Notification cancelled.")
                Exit While
            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.")
                Exit While
            End If

            ' Check for a notification of a completed collection.
            s = GC.WaitForFullGCComplete
            If (s = GCNotificationStatus.Succeeded) Then
                Console.WriteLine("GC Notifiction raised.")
                OnFullGCCompleteEndNotify()
            ElseIf (s = GCNotificationStatus.Canceled) Then
                Console.WriteLine("GC Notification cancelled.")
                Exit While
            Else
                ' Could be a time out.
                Console.WriteLine("GC Notification not applicable.")
                Exit While
            End If

        End While
        Thread.Sleep(500)
        ' FinalExit is set to true right before  
        ' the main thread cancelled notification.
        If finalExit Then
            Exit While
        End If

    End While
End Sub

설명

메서드를 RegisterForFullGCNotification 사용하여 전체 가비지 수집 알림을 등록합니다. 그런 다음 메서드 또는 메서드를 WaitForFullGCComplete 사용하여 WaitForFullGCApproach 알림 상태가 포함된 열거형을 반환 GCNotificationStatus 합니다.

적용 대상

추가 정보