private void CompletedDelegateFunc_Odd(object operationState) { GetOddNumbersArgs arg = operationState as GetOddNumbersArgs; //Executes a delegate on the thread that owns the control's underlying window handle GetOddNumbers_Completed?.Invoke(this, arg); }
private static void OddNumbersWorker(int min, int max, AsyncOperation asyncOp) { for (int i = min; i <= max; i++) { Thread.Sleep(1000); if (i % 2 != 0) { Console.Write($"{i} is odd!\n"); } } Console.WriteLine("Done with the odds!"); lock (tasks.SyncRoot) { tasks.Remove(asyncOp.UserSuppliedState); } GetOddNumbersArgs arg = new GetOddNumbersArgs(null, false, asyncOp.UserSuppliedState); asyncOp.PostOperationCompleted(onCompetedDelegate_Odd, arg); }