예제 #1
0
        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);
        }
예제 #2
0
 private static void primeNumberCalculator1_CalculatePrimeCompleted(object sender, CalculatePrimeCompletedEventArgs e)
 {
     if (e.Cancelled)
     {
     }
     else if (e.Error != null)
     {
     }
 }
예제 #3
0
        private void CalculateCompleted(object operationState)
        {
            CalculatePrimeCompletedEventArgs e = operationState as CalculatePrimeCompletedEventArgs;

            CalculatePrimeCompleted?.Invoke(this, e);
        }