Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

GCNotificationStatus Enumeration

Provides information about the current registration for notification of the next full garbage collection.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
[SerializableAttribute]
public enum GCNotificationStatus
Member nameDescription
CanceledThe current registration was canceled by the user.
FailedThe notification failed for any reason.
NotApplicableThis result can be caused by the following: there is no current registration for a garbage collection notification, concurrent garbage collection is enabled, or the time specified for the millisecondsTimeout parameter has expired and no garbage collection notification was obtained. (See the <gcConcurrent> runtime setting for information about how to disable concurrent garbage collection.)
SucceededThe notification was successful and the registration was not canceled.
TimeoutThe time specified by the millisecondsTimeout parameter for either GC.WaitForFullGCApproach(Int32) or GC.WaitForFullGCComplete(Int32) has elapsed.

Use the RegisterForFullGCNotification method to register for a full garbage collection notification. Then use the WaitForFullGCApproach method or the WaitForFullGCComplete method to return a GCNotificationStatus enumeration that contains the status of the notification.

The following example obtains a GCNotificationStatus enumeration from the WaitForFullGCApproach method. If the enumeration returns Succeeded, it calls the custom method OnFullGCApproachNotify to perform actions in response to the approaching full garbage collection. This code example is part of a larger example provided for Garbage Collection Notifications topic.

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.
            s = GC.WaitForFullGCComplete();
            if (s == GCNotificationStatus.Succeeded)
            {
                Console.WriteLine("GC Notifiction 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;
        }
    }

}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5 SP1, 3.0 SP2, 2.0 SP2

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.