/// <summary> /// This function will be called by SendOrPostCallback to raise Method1Completed Event /// </summary> /// <param name="operationState">Method1CompletedEventArgs object</param> private void CalculateCompleted(object operationState) { MathMulCompletedEventArgs e = operationState as MathMulCompletedEventArgs; if (MathMulCompleted != null) { MathMulCompleted(this, e); } }
/// <summary> /// This method does the actual work /// </summary> /// <param name="message"></param> /// <param name="asyncOp"></param> private void MathMulWorker(double[][] mat1, double[][] mat2, AsyncOperation asyncOp) { double[][] mat_res = MatMultiply(mat1, mat2); lock (tasks.SyncRoot) { tasks.Remove(asyncOp.UserSuppliedState); } MathMulCompletedEventArgs e = new MathMulCompletedEventArgs(mat1, mat2, mat_res, null, false, asyncOp.UserSuppliedState); asyncOp.PostOperationCompleted(onCompletedDelegate, e); }
private void CompletionMethod(double[][] mat1, double[][] mat2, double[][] mat_res, Exception exception, bool canceled, AsyncOperation asyncOp) { // If the task was not previously canceled, // remove the task from the lifetime collection. if (!canceled) { lock (userStateToLifetime.SyncRoot) { userStateToLifetime.Remove(asyncOp.UserSuppliedState); } } // Package the results of the operation in a // CalculatePrimeCompletedEventArgs. MathMulCompletedEventArgs e = new MathMulCompletedEventArgs(mat1, mat2, mat_res, exception, canceled, asyncOp.UserSuppliedState); // End the task. The asyncOp object is responsible // for marshaling the call. asyncOp.PostOperationCompleted(onCompletedDelegate, e); // Note that after the call to OperationCompleted, // asyncOp is no longer usable, and any attempt to use it // will cause an exception to be thrown. }