public void Dispose()
{
if (Interlocked.CompareExchange(ref m_disposeState, (int)DisposeState.Disposing, 0) == (int)DisposeState.Disposing)
return;
// If this poller is already started, signal the polling thread to stop
// and wait for it.
if (IsRunning)
{
m_stopSignaler.RequestStop();
m_switch.WaitForOff();
Debug.Assert(!IsRunning);
}
m_stopSignaler.Dispose();
#if !NET35
m_tasksQueue.Dispose();
#endif
foreach (var socket in m_sockets)
socket.EventsChanged -= OnSocketEventsChanged;
m_disposeState = (int)DisposeState.Disposed;
}