What does BlockingCollection.Dispose actually do?

What does BlockingCollection.Dispose actually do?

+7
source share
3 answers

This allows you to delete internal wait descriptors.

BlockingCollection<T> , inside, uses a pair of event wait descriptors, which in turn have a native HANDLE .

In particular, BlockingCollection<T>.Dispose() releases these two handles back to the operating system, eventually (via SemaphoreSlim-> ManualResetEvent), calling its own CloseHandle method in two instances of native HANDLE .

+9
source share

A quick view with a reflector shows this ...

 protected virtual void Dispose(bool disposing) { if (!this.m_isDisposed) { if (this.m_freeNodes != null) { this.m_freeNodes.Dispose(); } this.m_occupiedNodes.Dispose(); this.m_isDisposed = true; } } 

and m_freeNodes - private SemaphoreSlim m_freeNodes; , therefore, it frees up SemaphoreSlim, which are used internally.

+4
source share

Releases all resources used by the current instance of the BlockingCollection<T> class. ( Source )

-4
source share

All Articles