Пример #1
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        public void Dispose()
        {
            lock (_sync)
            {
                if (_processQueueThread != null && _processQueueThread.IsAlive)
                {
                    try
                    {
                        if (!_processQueueThread.Join(TimeSpan.FromSeconds(1)))
                        {
                            _processQueueThread.Abort();
                        }
                    }
                    catch (Exception err)
                    {
                        Log.Error(err);
                    }
                }

                foreach (var worker in _workers)
                {
                    worker.DisposeSafely();
                }

                _holdQueue?.DisposeSafely();
                _processQueue?.DisposeSafely();

                // if IsClosed means its already disposed
                if (_waitHandle != null && !_waitHandle.SafeWaitHandle.IsClosed)
                {
                    _waitHandle.Set();
                    _waitHandle.DisposeSafely();
                }
            }
        }