Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BlockingCollection<myEventArgs> myTasks = new BlockingCollection<myEventArgs>();
- private void myEventHandler(object sender, myEventArgs e)
- {
- myTasks.Add(e);
- }
- private void doWork()
- {
- while (myTasks.IsCompleted == false)
- {
- //Do some work here with the third party API.
- var eArgs = myTasks.Take();
- //Sometimes I have a background (thread safe) task to perform.
- //This is submitted to the thread pool.
- Task.Run(() => doSomeBackgroundWork());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement