Ejemplo n.º 1
0
        public static void CallPassDataToMethodAndRetrieveUsingCallBackMethod()
        {
            //Prompt the user to enter target number.
            Console.WriteLine("Enter target number:");
            //Read from the console and store it in target variable.
            int targ = Convert.ToInt32(Console.ReadLine());
            //Create an instance of the callback delegate and to its constructor pass the name of the callback function.
            SumOfNumberCallBack sumNumberCallback = new SumOfNumberCallBack(PrintSumOfNumbers);

            //Create the instance of the number class and to it's constructor pass the target number and instance of the callback delegate.
            CallbackDelegateDemoToRetrievData obj = new CallbackDelegateDemoToRetrievData(targ, sumNumberCallback);

            //Create an instance of the thread class and specify the Thread function to invoke.
            Thread t7 = new Thread(new ThreadStart(obj.ComputeSumOfNumbers));

            t7.Start();
        }
Ejemplo n.º 2
0
 //callback to initialize the target number and callback delegate.
 public CallbackDelegateDemoToRetrievData(int target, SumOfNumberCallBack delcallback)
 {
     this._target = target;
     this._sumOfNumberCallback = delcallback;
 }