示例#1
0
 /// <summary>
 /// Produce a queued item.
 /// </summary>
 /// <param name="item">item to queue</param>
 public void Produce(T item)
 {
     if (IsRunning)
     {
         _queue.Enqueue(item);
     }
 }
示例#2
0
        public void ReaderWriterQueueTest()
        {
            var producer   = new ReaderWriterQueue <string>();
            var resetEvent = new ManualResetEventSlim(false);

            var _ = Task.Factory.StartNew(() =>
            {
                var item = producer.Dequeue();
                Assert.Equal("This is a message", item);
                // ReSharper disable once AccessToDisposedClosure
                resetEvent.Set();
            });

            producer.Enqueue("This is a message");
            resetEvent.Wait();
            resetEvent.Dispose();
        }