示例#1
0
 public void Dispose()
 {
     if (_queue == null || _parentLogger != null)
     {
         return;
     }
     try
     {
         if (!_queue.EmptiedWaitHandle.WaitOne(TimeSpan.FromMinutes(1), false))
         {
             const string MSG = "Could not wait for underflowing of event queue '{0}'. Remaining events: {1}";
             if (this != CoreApplication.Instance.Logger)
             {
                 CoreApplication.Instance.Logger.LogError(MSG, LoggerName, _queue.Count);
             }
             else
             {
                 LoggingUtils.LogToConsole(MSG, LoggerName, _queue.Count);
             }
         }
     }
     catch (ObjectDisposedException)
     {
     }
     _queue.Dispose();
 }
示例#2
0
        //[TestMethod]
        //[Ignore("Old behaviour is not good. Changing it can break production code. This test should be enabled when BlockingQueue dispose logic will be updated")]
        public void TestDisposeInterruptWaitersOnAdd()
        {
            BlockingQueue <int> queue = new BlockingQueue <int>(2);

            queue.Add(1);
            queue.Add(2);
            Barrier bar = new Barrier(2);

            Task disposeTask = Task.Run(() =>
            {
                bar.SignalAndWait();
                Thread.Sleep(10);
                queue.Dispose();
            });

            try
            {
                bar.SignalAndWait();
                bool added = queue.TryAdd(3, 10000);
                Assert.Fail();
            }
            catch (OperationInterruptedException)
            {
            }
            catch (ObjectDisposedException)
            {
            }
            catch (Exception)
            {
                Assert.Fail("Unexpected exception");
            }


            disposeTask.Wait();
        }
        BlockingQueue_TryDequeue_Throw_ObjectDisposedException_With_Milliseconds_When_BlockingQueue_is_Disposed()
        {
            //Arrange
            var blockingQueue = new BlockingQueue <int>();

            //Act
            blockingQueue.Dispose();
            blockingQueue.TryDequeue(out int item, 0);

            //Assert is handled by the ExpectedException
        }
示例#4
0
        public void Dispose()
        {
            if (_isDisposed)
            {
                return;
            }

            _worksQueue.Dispose();

            _isDisposed = true;
        }
        BlockingQueue_TryPeek_Throw_ObjectDisposedException_With_Milliseconds_and_CancellationToken_When_BlockingQueue_is_Disposed()
        {
            //Arrange
            var blockingQueue = new BlockingQueue <int>();

            //Act
            blockingQueue.Dispose();
            blockingQueue.TryPeek(out int item, 0, CancellationToken.None);

            //Assert is handled by the ExpectedException
        }
        public void BlockingQueue_TryPeek_Throw_ObjectDisposedException_With_TimeSpan_When_BlockingQueue_is_Disposed()
        {
            //Arrange
            var blockingQueue = new BlockingQueue <int>();

            //Act
            blockingQueue.Dispose();
            blockingQueue.TryPeek(out int item, new TimeSpan(0));

            //Assert is handled by the ExpectedException
        }
        public void BlockingQueue_Enqueue_Throw_ObjectDisposedException_When_BlockingQueue_is_Disposed()
        {
            //Arrange
            var blockingQueue = new BlockingQueue <int>();

            //Act
            blockingQueue.Dispose();
            blockingQueue.Enqueue(22);

            //Assert is handled by the ExpectedException
        }
        BlockingQueue_ToArray_Convert_Collection_to_Array_Throw_ObjectDisposedException_When_Collection_is_Disposed()
        {
            //Arrange
            var blockingQueue = new BlockingQueue <int>();

            blockingQueue.Dispose();

            //Act
            var array = blockingQueue.ToArray();

            //Assert is handled by the ExpectedException
        }
        public void BlockingQueue_Get_Count_Collection_Throw_ObjectDisposedException_When_Collection_is_Disposed()
        {
            //Arrange
            var blockingQueue = new BlockingQueue <int>();

            blockingQueue.Dispose();

            //Act
            var count = blockingQueue.Count;

            //Assert is handled by the ExpectedException
        }
示例#10
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         pr.Close();
         pw.Close();
         st.Close();
         socket.Close();
         receiveQueue.Dispose();
         transmitQueue.Dispose();
     }
 }
示例#11
0
        public void Use_Disposed_Queue()
        {
            var queue = new BlockingQueue <int>();

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            Task.Run(() =>
            {
                Thread.Sleep(1000);
                queue.Dispose();
            });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            queue.Dequeue(new CancellationTokenSource(TimeSpan.FromSeconds(2)).Token);
        }
        /** @copydoc BaseDataLayer::dispose */
        protected override void dispose()
        {
            m_internalThread.StopInternalThread();

            if (m_rgPrefetchFull != null)
            {
                m_rgPrefetchFull.Dispose();
                m_rgPrefetchFull = null;
            }

            if (m_rgPrefetchFree != null)
            {
                m_rgPrefetchFree.Dispose();
                m_rgPrefetchFree = null;
            }

            base.dispose();
        }
示例#13
0
        public void Queue()
        {
            BlockingQueue<string> queue = new BlockingQueue<string>();

            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += new DoWorkEventHandler(DoWork);
            worker.ProgressChanged += new ProgressChangedEventHandler(DoProgressChanged);
            worker.WorkerReportsProgress = true;
            worker.RunWorkerAsync(queue);

            int count = 0;
            while (count < 5)
            {
                string s = queue.Dequeue();
                Console.WriteLine("dequeued " + count + "(" + s + ")");
                count++;
            }

            queue.Clear();
            queue.Dispose();
            queue = null;
        }
 /// <summary>
 /// Release the threads associated with this pool; if additional work is requested, it will
 /// be sent to the main thread-pool
 /// </summary>
 public void Dispose()
 {
     _disposed = true;
     _queue.Dispose();
 }
 public virtual void Dispose()
 {
     _source.Cancel();
     _source.Dispose();
     _queue.Dispose();
 }
示例#16
0
 public void Dispose()
 {
     blockingQueue?.Dispose();
 }
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     _queue.Dispose();
 }