コード例 #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();
        }
コード例 #3
0
        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;
        }
コード例 #5
0
        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
        }
コード例 #6
0
        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
        }
コード例 #7
0
        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
        }
コード例 #8
0
        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
        }
コード例 #9
0
        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
ファイル: SshSocket.cs プロジェクト: neoscrib/secureshell
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         pr.Close();
         pw.Close();
         st.Close();
         socket.Close();
         receiveQueue.Dispose();
         transmitQueue.Dispose();
     }
 }
コード例 #11
0
ファイル: BlockingQueue_Tests.cs プロジェクト: zz110/MQTTnet
        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);
        }
コード例 #12
0
        /** @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
ファイル: BlockQueueTests.cs プロジェクト: pengyancai/cs-util
        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;
        }
コード例 #14
0
 /// <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();
 }
コード例 #15
0
 public virtual void Dispose()
 {
     _source.Cancel();
     _source.Dispose();
     _queue.Dispose();
 }
コード例 #16
0
 public void Dispose()
 {
     blockingQueue?.Dispose();
 }
コード例 #17
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     _queue.Dispose();
 }