Guest User

Untitled

a guest
Jun 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. class WorkQueue
  2. {
  3. ConcurrentQueue<WorkItem> q = new ConcurrentQueue<WorkItem>();
  4.  
  5. AutoResetEvent semaphore = new AutoResetEvent(false);
  6.  
  7. public void DoWork()
  8. {
  9. for (; ; )
  10. {
  11. semaphore.WaitOne(60 * 1000);
  12. WorkItem workItem;
  13. while (q.TryDequeue(out workItem))
  14. {
  15. workItem.DoAsyncWork();
  16. }
  17. }
  18. }
  19.  
  20. public void AddWork(WorkItem workItem)
  21. {
  22. q.Enqueue(workItem);
  23. semaphore.Set();
  24. }
  25. }
  26.  
  27. public abstract class WorkItem
  28. {
  29. public abstract void DoAsyncWork();
  30. }
Add Comment
Please, Sign In to add comment