Thread.DisableComObjectEagerCleanup Method

Definition

Turns off automatic cleanup of runtime callable wrappers (RCW) for the current thread.

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

Remarks

By default, the common language runtime (CLR) cleans up runtime callable wrappers automatically. The CLR pumps messages during the cleanup, which might cause reentrancy problems for a few applications that meet the following unusual criteria:

  • The application does its own message pumping.

  • The application needs to control precisely when message pumping occurs.

Such applications can use the DisableComObjectEagerCleanup method to prevent the CLR from doing automatic reclamation of runtime callable wrappers.

When this method has been called on a thread, automatic cleanup cannot be re-enabled for that thread. When your application is ready to clean up runtime callable wrappers, use the Marshal.CleanupUnusedObjectsInCurrentContext method to instruct the runtime to clean up all runtime callable wrappers in the current context. Message pumping occurs while the method executes.

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 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