Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

39 lines (35 sloc) 976 Bytes
using System.Collections.Generic;
using System.Threading;
namespace S22.Imap {
/// <summary>
/// A thread-safe Queue
/// </summary>
internal class SafeQueue<T> {
private readonly Queue<T> _queue = new Queue<T>();
/// <summary>
/// Adds an object to the end of the queue.
/// </summary>
/// <param name="item">The object to add to the queue.</param>
public void Enqueue(T item) {
lock (_queue) {
if (_queue.Count == 1)
/// <summary>
/// Removes and returns the object at the beginning of the queue. If
/// the queue is empty, the method blocks the calling thread until an
/// object is put into the queue by another thread.
/// </summary>
/// <returns>The object that is removed from the beginning
/// of the queue.</returns>
public T Dequeue() {
lock (_queue) {
while (_queue.Count == 0)
return _queue.Dequeue();
Jump to Line
Something went wrong with that request. Please try again.