Created
October 25, 2010 10:15
-
-
Save anonymous/644721 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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