英語で読む

次の方法で共有


GCNotificationStatus 列挙型

定義

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

C#
public enum GCNotificationStatus
C#
[System.Serializable]
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 パラメーターで指定した時間が経過しました。

次の例では、 メソッドから 列挙体をWaitForFullGCApproach取得GCNotificationStatusします。 列挙体が Succeeded を返す場合は、カスタム メソッド OnFullGCApproachNotify を呼び出して、近づいている完全なガベージ コレクションに応答してアクションを実行します。 このコード例は、 ガベージ コレクション通知 に関するトピックで提供されるより大きな例の一部です。

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

注釈

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

適用対象

製品 バージョン
.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

こちらもご覧ください