SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top