Läs på engelska Redigera

Dela via


GC.WaitForFullGCComplete Method

Definition

Returns the status of a registered notification for determining whether a full, blocking garbage collection by the common language runtime has completed.

Overloads

WaitForFullGCComplete()

Returns the status of a registered notification for determining whether a full, blocking garbage collection by the common language runtime has completed.

WaitForFullGCComplete(Int32)

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

WaitForFullGCComplete(TimeSpan)

Returns the status of a registered notification about whether a blocking garbage collection has completed. May wait indefinitely for a full collection.

WaitForFullGCComplete()

Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs

Returns the status of a registered notification for determining whether a full, blocking garbage collection by the common language runtime has completed.

public static GCNotificationStatus WaitForFullGCComplete ();
[System.Security.SecurityCritical]
public static GCNotificationStatus WaitForFullGCComplete ();

Returns

The status of the registered garbage collection notification.

Attributes

Examples

The following example shows how to use this method to determine whether a full garbage collection has completed. Whenever the status of the notification is Succeeded, the user method OnFullGCCompletedNotify is called to perform actions in response to the completed collection. This code example is part of a larger example provided for Garbage Collection Notifications topic.

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

Remarks

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 WaitForFullGCApproach method to determine whether a full garbage collection is imminent.

When the enumeration returns Succeeded, you can do tasks such as resuming work and obtaining a collection count with the CollectionCount property.

This method waits indefinitely for a garbage collection notification to be obtained. If you want to specify a time-out period for the method to return if the notification cannot be obtained, use the GC.WaitForFullGCApproach(Int32) method overload. If you call this method without specifying a time-out, you can call the CancelFullGCNotification method if you are waiting longer than preferred.

This method call should be preceded with a call to the WaitForFullGCApproach method to make sure that you have had a full garbage collection. Calling this method alone can produce indeterminate results.

See also

Applies to

.NET 9 och andra versioner
Produkt Versioner
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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, 4.8.1
.NET Standard 2.0, 2.1

WaitForFullGCComplete(Int32)

Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs

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

public static GCNotificationStatus WaitForFullGCComplete (int millisecondsTimeout);
[System.Security.SecurityCritical]
public static GCNotificationStatus WaitForFullGCComplete (int millisecondsTimeout);

Parameters

millisecondsTimeout
Int32

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

Returns

The status of the registered garbage collection notification.

Attributes

Exceptions

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

Remarks

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 WaitForFullGCApproach method to determine whether a full garbage collection is imminent.

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 resuming work and obtaining a collection count with the CollectionCount property.

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

This method call should be preceded with a call to the WaitForFullGCApproach method to make sure that you have had a full garbage collection. Calling this method alone can produce indeterminate results.

See also

Applies to

.NET 9 och andra versioner
Produkt Versioner
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.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, 4.8.1
.NET Standard 2.0, 2.1

WaitForFullGCComplete(TimeSpan)

Source:
GC.cs
Source:
GC.cs
Source:
GC.cs

Returns the status of a registered notification about whether a blocking garbage collection has completed. May wait indefinitely for a full collection.

public static GCNotificationStatus WaitForFullGCComplete (TimeSpan timeout);

Parameters

timeout
TimeSpan

The timeout on waiting for a full collection

Returns

The status of a registered full GC notification

Applies to

.NET 9 och andra versioner
Produkt Versioner
.NET 7, 8, 9