This documentation is archived and is not being maintained.

GC.WaitForFullGCApproach Method (Int32)

Updated: July 2008

Returns, in a specified time-out period, the status of a registered notification for determining whether a full garbage collection by the common language runtime is imminent.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
public static GCNotificationStatus WaitForFullGCApproach(
	int millisecondsTimeout


Type: System.Int32

The length of time to wait before a notification status can be obtained. Specify -1 to wait indefinitely.

Return Value

Type: System.GCNotificationStatus
The status of the registered garbage collection notification.


millisecondsTimeout must be either non-negative or less than or equal to MaxValue or -1.

Use the GCNotificationStatus enumeration returned by this method to determine the status of the current garbage collection notification that was registered by using the RegisterForFullGCNotification method. You can also use the WaitForFullGCComplete method to determine whether the full garbage collection has completed.

Note that this method returns immediately whenever a garbage collection notification status is obtained, regardless of the value specified by millisecondsTimeout. If a garbage collection notification status is not obtained before millisecondsTimeout times out, this method returns NotApplicable.

When the enumeration returns Succeeded, you can do tasks such as preventing additional objects from being allocated and inducing a collection yourself with the Collect method. Note that the notification does not guarantee that a full garbage collection will occur, only that conditions have reached the threshold that are favorable for a full garbage collection to occur.

You can call the CancelFullGCNotification method when you cannot wait for the time-out period to elapse.

You should follow this method with a call to the WaitForFullGCComplete method to make sure that you have had a full garbage collection. Calling this method alone causes indeterminate results.

  • LinkDemand 

    for full trust for the immediate caller. This member cannot be used by partially trusted code.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5 SP1, 3.0 SP2, 2.0 SP2




July 2008

Added topic.

SP1 feature change.