What does BlockingCollection.Dispose actually do?
A:
Releases all resources used by the current instance of the
BlockingCollection<T>
class. (Source)
Justice
2010-07-06 17:24:31
That's true, but vague...
Reed Copsey
2010-07-06 17:25:57
-1. This is unhelpful.
Adam Robinson
2010-07-06 17:32:45
+4
A:
This allows the internal wait handles to be disposed of properly.
BlockingCollection<T>
, internally, uses a pair of event wait handles, which in turn have an associated native HANDLE
.
Specifically, BlockingCollection<T>.Dispose()
releases these two handles back to the operating system, by eventually (through SemaphoreSlim->ManualResetEvent) calling the native CloseHandle method on the two native HANDLE
instances.
Reed Copsey
2010-07-06 17:25:45
+3
A:
Having a quick look with reflector reveals 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
is private SemaphoreSlim m_freeNodes;
so it releases the SemaphoreSlim that are used internally.
Andy Robinson
2010-07-06 17:30:08