Example #1
0
        //Called by SnedOrPostCallback
        //raise GetEvenNumbers_Completed
        private void CompletedDelegateFunc_Even(object operationState)
        {
            GetEvenNumberEventArgs arg = operationState as GetEvenNumberEventArgs;

            //Checks if GetEvenNumbers_Completed is empty (but then shortend notation)
            GetEvenNumbers_Completed?.Invoke(this, arg);
        }
Example #2
0
        //Does the actual work
        private static void EvenNumbersWorker(int min, int max, AsyncOperation asyncOp)
        {
            for (int i = min; i <= max; i++)
            {
                Thread.Sleep(3000);
                if (i % 2 == 0)
                {
                    Console.Write($"{i} is even!\n");
                }
            }

            Console.WriteLine("Done with the evens!");
            //SyncRoot gets an object that can be used to
            //synchronize acces to the HybridDictionary
            lock (tasks.SyncRoot)
            {
                //UserSuppliedState gets or sets an object used to uniquely
                //identify an async operation
                tasks.Remove(asyncOp.UserSuppliedState);
            }

            GetEvenNumberEventArgs arg = new GetEvenNumberEventArgs(null, false, asyncOp.UserSuppliedState);

            asyncOp.PostOperationCompleted(onCompletedDelegate_Even, arg);
        }