Skip to content

Instantly share code, notes, and snippets.

Created October 25, 2010 10:15
Show Gist options
  • Save anonymous/644721 to your computer and use it in GitHub Desktop.
Save anonymous/644721 to your computer and use it in GitHub Desktop.
class WorkQueue
{
ConcurrentQueue<WorkItem> q = new ConcurrentQueue<WorkItem>();
AutoResetEvent semaphore = new AutoResetEvent(false);
public void DoWork()
{
for (; ; )
{
semaphore.WaitOne(60 * 1000);
WorkItem workItem;
while (q.TryDequeue(out workItem))
{
workItem.DoAsyncWork();
}
}
}
public void AddWork(WorkItem workItem)
{
q.Enqueue(workItem);
semaphore.Set();
}
}
public abstract class WorkItem
{
public abstract void DoAsyncWork();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment