Advertisement
exqxste

MyTaskCompleted­Callback method

Jul 10th, 2020
1,816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. // Made by CelestialTwist
  2.  
  3. private void MyTaskCompletedCallback(IAsyncResult ar)
  4. {
  5.   // get the original worker delegate and the AsyncOperation instance
  6.   MyTaskWorkerDelegate worker =
  7.     (MyTaskWorkerDelegate)((AsyncResult)ar).AsyncDelegate;
  8.   AsyncOperation async = (AsyncOperation)ar.AsyncState;
  9.  
  10.   // finish the asynchronous operation
  11.   worker.EndInvoke(ar);
  12.  
  13.   // clear the running task flag
  14.   lock (_sync)
  15.   {
  16.     _myTaskIsRunning = false;
  17.   }
  18.  
  19.   // raise the completed event
  20.   AsyncCompletedEventArgs completedArgs = new AsyncCompletedEventArgs(null,
  21.     false, null);
  22.   async.PostOperationCompleted(
  23.     delegate(object e) { OnMyTaskCompleted((AsyncCompletedEventArgs)e); },
  24.     completedArgs);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement