Language

GCNotificationStatus 列挙型

定義

次の完全ガベージ コレクションの通知に関する現在の登録に関する情報を提供します。

public enum class GCNotificationStatus
public enum GCNotificationStatus
[System.Serializable]
public enum GCNotificationStatus
type GCNotificationStatus = 
[<System.Serializable>]
type GCNotificationStatus = 
Public Enum GCNotificationStatus
継承
GCNotificationStatus
属性

フィールド

名前 値 説明
Succeeded 0

通知が成功し、登録が取り消されませんでした。

Failed 1

何らかの理由で通知に失敗しました。

Canceled 2

現在の登録はユーザーによって取り消されました。

Timeout 3

millisecondsTimeoutまたはWaitForFullGCApproach(Int32)の WaitForFullGCComplete(Int32) パラメーターで指定された時間が経過しました。

NotApplicable 4

この値は、ガベージ コレクション通知の現在の登録がない場合、または完全な GC が発生したが、完全なブロック GC ではなくバックグラウンド GC (つまり、ユーザー スレッドとほぼ同時に実行される GC) として実行された場合に発生する可能性があります。 バックグラウンド GC は既定で有効になっています。これを無効にすると予測精度が向上しますが、GC の一時停止が大きくなります。

例

次の例では、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 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 メソッドを使用して、完全なガベージ コレクション通知を登録します。 次に、 WaitForFullGCApproach メソッドまたは WaitForFullGCComplete メソッドを使用して、通知の状態を含む GCNotificationStatus 列挙体を返します。

適用対象

こちらもご覧ください