GC.EndNoGCRegion Method

Definition

Ends the no GC region latency mode.

public static void EndNoGCRegion ();
[System.Security.SecurityCritical]
public static void EndNoGCRegion ();
Attributes

Exceptions

The garbage collector is not in no GC region latency mode.

-or-

The no GC region latency mode was ended previously because a garbage collection was induced.

-or-

A memory allocation exceeded the amount specified in the call to the TryStartNoGCRegion(Int64) method.

Remarks

The EndNoGCRegion method throws an InvalidOperationException if the garbage collector is not in no GC region latency mode. This occurs under any of the following conditions:

You can prevent an exception for any of these reasons by using code such as the following:

if (GCSettings.LatencyMode == GCLatencyMode.NoGCRegion)
   GC.EndNoGCRegion();

Applies to

产品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 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

See also