You can't tell the Garbage Collector when to finalize an object or what thread to finalize an object on.
You can tell the Garbage Collector that now would be a good time to collect by calling GC.Collect
.
You can tell the Garbage Collector that an object that fully and properly implements IDisposable
, does not need to be finalized by calling GC.SuppressFinalize
when IDisposable.Dispose
is called directly.
Once again, you cannot control when, other than suppressing, or on what thread that an objects finalizer will be run.
Your Finalizer/Destructor and protected Dispose(bool disposing)
implementation have to be aware of this limitation and handle cross-thread and null checks appropriately.