Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. BlockingCollection<myEventArgs> myTasks = new BlockingCollection<myEventArgs>();
  2.  
  3. private void myEventHandler(object sender, myEventArgs e)
  4. {
  5. myTasks.Add(e);
  6. }
  7.  
  8. private void doWork()
  9. {
  10.  
  11. while (myTasks.IsCompleted == false)
  12. {
  13.  
  14. //Do some work here with the third party API.
  15. var eArgs = myTasks.Take();
  16.  
  17. //Sometimes I have a background (thread safe) task to perform.
  18. //This is submitted to the thread pool.
  19. Task.Run(() => doSomeBackgroundWork());
  20.  
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement