private void CalculateWorker(int numberToTest, AsyncOperation asyncOp) { bool isPrime = false; int firstDivisor = 1; Exception e = null; if (!TaskCanceled(asyncOp.UserSuppliedState)) { try { ArrayList primes = BuildPrimeNumberList(numberToTest, asyncOp); isPrime = IsPrime(primes, numberToTest, out firstDivisor); } catch (Exception ex) { e = ex; } } if (!TaskCanceled(asyncOp.UserSuppliedState)) { lock (userStateToLifetime.SyncRoot) { userStateToLifetime.Remove(asyncOp.UserSuppliedState); } } CalculatePrimeCompletedEventArgs eventArgs = new CalculatePrimeCompletedEventArgs(e, TaskCanceled(asyncOp.UserSuppliedState), asyncOp.UserSuppliedState); asyncOp.PostOperationCompleted(onCompletedDelegate, eventArgs); }
private static void primeNumberCalculator1_CalculatePrimeCompleted(object sender, CalculatePrimeCompletedEventArgs e) { if (e.Cancelled) { } else if (e.Error != null) { } }
private void CalculateCompleted(object operationState) { CalculatePrimeCompletedEventArgs e = operationState as CalculatePrimeCompletedEventArgs; CalculatePrimeCompleted?.Invoke(this, e); }