コード例 #1
0
ファイル: Task.cs プロジェクト: emret/AsyncSample
        private void MyTaskCompletedCallback(IAsyncResult ar)
        {
            // get the original worker delegate and the AsyncOperation instance
            MyTaskWorkerDelegate worker = (MyTaskWorkerDelegate)((AsyncResult)ar).AsyncDelegate;
            AsyncOperation async = (AsyncOperation)ar.AsyncState;
            bool cancelled;

            // finish the asynchronous operation
            worker.EndInvoke(out cancelled, ar);

            // clear the running task flag
            lock (_sync)
            {
                _myTaskIsRunning = false;
                _myTaskContext = null;
            }

            // raise the completed event
            MyTaskAsyncCompletedEventArgs completedArgs = new MyTaskAsyncCompletedEventArgs(null, cancelled, null, Id);
            async.PostOperationCompleted(delegate(object e) { OnMyTaskCompleted((MyTaskAsyncCompletedEventArgs)e); }, completedArgs);
        }
コード例 #2
0
ファイル: Task.cs プロジェクト: emret/AsyncSample
 protected virtual void OnMyTaskCompleted(MyTaskAsyncCompletedEventArgs e)
 {
     if (MyTaskCompleted != null)
         MyTaskCompleted(this, e);
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: emret/AsyncSample
 static void task_MyTaskCompleted(object sender, MyTaskAsyncCompletedEventArgs e)
 {
     Console.WriteLine("Main : task[{0}] completed :) ", e.Id);
 }