/// <summary> /// Constructor. /// </summary> /// <param name="pool">The thread pool where threads will be pulled from to execute the message handler.</param> /// <param name="name">A name for this queue. Can be used to determine what message queue is running if more than one queue is running on a threadpool.</param> public MessageQueue(IArrowThreadPool pool, string name) { if (null == pool) { throw new ArgumentNullException("pool"); } _pool = pool; if (null == name) { throw new ArgumentNullException("name"); } Name = name; _messageQueueId = Interlocked.Increment(ref _nextMessageQueueId); _messageQueue = new Queue <MessageObject>(); _notProcessing = true; _guard = new ExecutionGuard(); }
protected virtual void Dispose(bool isDisposing) { if (_guard.IsDisabled) { return; } if (isDisposing) { // shutdown the whole process. Will no longer handle messages. _guard.DisableExecute(); // kill unhandled messages. No need for a lock since it can't be // reached by the public methods anymore. _messageQueue.Clear(); // do not dispose it! It's not owned by the messageQueue. _pool.CancelTimeoutByReceiver(this); _pool = null; // clear the message handle to allow this to dispose. Don't want // stray references to outside objects. _currentMessageHandler = null; } }