Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
Add Comment
Please, Sign In to add comment