Exemple #1
0
        // method name should begin with big letter, why static?? why new class??
        public static void callbackMethod(IAsyncResult Iasync)
        {
            AsyncResult     res          = (AsyncResult)Iasync;
            CallbackClass   callback     = new CallbackClass();
            currentDelegate caller       = (currentDelegate)res.AsyncDelegate;
            var             PrimeNumbers = caller.EndInvoke(Iasync);

            foreach (var number in PrimeNumbers)
            {
                callback.addToList(number);
            }
        }
Exemple #2
0
        // method name should begin with big letter
        private void callbackMethod(IAsyncResult Iasync)
        {
            // delete first 2 lines and define "PrimesCalculator" as parameter class
            AsyncResult     res          = (AsyncResult)Iasync;
            CallbackClass   callback     = new CallbackClass();
            currentDelegate caller       = (currentDelegate)res.AsyncDelegate;
            var             PrimeNumbers = caller.EndInvoke(Iasync);

            foreach (var num in PrimeNumbers)
            {
                // invoke - synchronic , beginInvoke - asynchronic
                // The UI is blocked
                Invoke((MethodInvoker) delegate
                {
                    listBox1.Items.Add(num);
                });
            }
        }