Пример #1
0
        public static void zad5()
        {
            delegateSilnia = new DelegateType(silniarek);
            IAsyncResult ar     = delegateSilnia.BeginInvoke(10, null, null);
            int          result = delegateSilnia.EndInvoke(ar);

            Console.WriteLine(result);
            delegateSilniait = new DelegateType(silniait);
            IAsyncResult arit = delegateSilnia.BeginInvoke(10, null, null);

            result = delegateSilnia.EndInvoke(arit);
            Console.WriteLine(result);
        }
Пример #2
0
        private static void zad8()
        {
            delegateName = new DelegateType(fib_r);


            IAsyncResult ar = delegateName.BeginInvoke(40, null, null);

            Console.WriteLine("Fibonacci rekurencyjnie=" + delegateName.EndInvoke(ar));

            delegateName = fib_i;
            IAsyncResult ar1 = delegateName.BeginInvoke(40, null, null);

            Console.WriteLine("Fibonacci iteracyjnie=" + delegateName.EndInvoke(ar1));

            delegateName = silnia_r;
            IAsyncResult ar2 = delegateName.BeginInvoke(20, null, null);

            Console.WriteLine("Silnia rekurencyjnie=" + delegateName.EndInvoke(ar2));

            delegateName = silnia_i;
            IAsyncResult ar3 = delegateName.BeginInvoke(20, null, null);

            Console.WriteLine("Silnia rekurencyjnie=" + delegateName.EndInvoke(ar3));

            Console.ReadKey();
        }
Пример #3
0
        static void Main(string[] args)
        {
            rSilniaDelegate    = new DelegateType(rSilnia);
            iSilniaDelegate    = new DelegateType(iSilnia);
            rFibonacciDelegate = new DelegateType(rFibonacci);
            iFibonacciDelegate = new DelegateType(iFibonacci);

            IAsyncResult rSilniaResult    = rSilniaDelegate.BeginInvoke(4, null, null);
            IAsyncResult iSilniaResult    = iSilniaDelegate.BeginInvoke(4, null, null);
            IAsyncResult rFibonacciResult = rFibonacciDelegate.BeginInvoke(4, null, null);
            IAsyncResult iFibonacciResult = iFibonacciDelegate.BeginInvoke(4, null, null);

            WaitHandle[] waitHandles = new WaitHandle[] { rSilniaResult.AsyncWaitHandle, iSilniaResult.AsyncWaitHandle,
                                                          rFibonacciResult.AsyncWaitHandle, iFibonacciResult.AsyncWaitHandle };

            WaitHandle.WaitAll(waitHandles);

            int rSilniaValue    = rSilniaDelegate.EndInvoke(rSilniaResult);
            int iSilniaValue    = iSilniaDelegate.EndInvoke(iSilniaResult);
            int rFibonacciValue = rFibonacciDelegate.EndInvoke(rFibonacciResult);
            int iFibonacciValue = iFibonacciDelegate.EndInvoke(iFibonacciResult);

            foreach (WaitHandle temp in waitHandles)
            {
                temp.Close();
            }

            Console.WriteLine("Rekurencyjnie silnia z 4: " + rSilniaValue + "\nIteracyjnie silnia z 4: " + iSilniaValue + "\nRekurencyjnie Fibonacci z 4: "
                              + rFibonacciValue + "\n" + "Iteracyjnie Fibonacci z 4: " + iFibonacciValue);
        }
Пример #4
0
        static void Main(string[] args)
        {
            recursionFactorialDelegate = new DelegateType(recursionFactorial);
            iterateFactorialDelegate   = new DelegateType(iterateFactorial);
            recursionFibonacciDelegate = new DelegateType(recursionFibonacci);
            iterateFibonacciDelegate   = new DelegateType(iterateFibonacci);

            IAsyncResult recursionFactorialResult = recursionFactorialDelegate.BeginInvoke(4, null, null);
            IAsyncResult iterateFactorialResult   = iterateFactorialDelegate.BeginInvoke(4, null, null);
            IAsyncResult recursionFibonacciResult = recursionFibonacciDelegate.BeginInvoke(4, null, null);
            IAsyncResult iterateFibonacciResult   = iterateFibonacciDelegate.BeginInvoke(4, null, null);

            WaitHandle[] waitHandles = new WaitHandle[] { recursionFactorialResult.AsyncWaitHandle, iterateFactorialResult.AsyncWaitHandle,
                                                          recursionFibonacciResult.AsyncWaitHandle, iterateFibonacciResult.AsyncWaitHandle };

            WaitHandle.WaitAll(waitHandles);

            int recursionFactorialValue = recursionFactorialDelegate.EndInvoke(recursionFactorialResult);
            int iterateFactorialValue   = iterateFactorialDelegate.EndInvoke(iterateFactorialResult);
            int recursionFibonacciValue = recursionFibonacciDelegate.EndInvoke(recursionFibonacciResult);
            int iterateFibonacciValue   = iterateFibonacciDelegate.EndInvoke(iterateFibonacciResult);

            foreach (WaitHandle temp in waitHandles)
            {
                temp.Close();
            }

            Console.WriteLine("Recursion factorial of 4: {0}\nIterate factorial of 4: {1}\nRecursion Fibonacci of 4: {2}\n" +
                              "Iterate Fibonacci of 4: {3}\n", recursionFactorialValue, iterateFactorialValue, recursionFibonacciValue,
                              iterateFibonacciValue);
        }
Пример #5
0
        public void Run()
        {
            const int nCount = 45;

            var counter = new Stopwatch();

            fact = new DelegateType(FibonacciRec);
            fib  = new DelegateType(FibonacciIter);

            counter.Start();

            fact.Invoke(nCount);
            fib.Invoke(nCount);

            counter.Stop();

            Console.WriteLine("Synch: " + counter.Elapsed);

            counter.Reset();
            counter.Start();

            var factAsync = fact.BeginInvoke(nCount, null, null);
            var fibAsync  = fib.BeginInvoke(nCount, null, null);

            fact.EndInvoke(factAsync);
            fib.EndInvoke(fibAsync);

            counter.Stop();

            Console.WriteLine("Asynch: " + counter.Elapsed);
        }
Пример #6
0
        static void Main(string[] args)
        {
            int i = 40;

            delegateRecursiveFib = new DelegateType(rFib);
            delegateIterativeFib = new DelegateType(iFib);

            Stopwatch stopWatch1 = new Stopwatch();

            stopWatch1.Start();
            IAsyncResult r_rFib = delegateRecursiveFib.BeginInvoke(i, null, null);
            int          r1     = delegateRecursiveFib.EndInvoke(r_rFib);

            stopWatch1.Stop();

            Stopwatch stopWatch2 = new Stopwatch();

            stopWatch2.Start();
            IAsyncResult r_iFib = delegateIterativeFib.BeginInvoke(i, null, null);
            int          r2     = delegateIterativeFib.EndInvoke(r_iFib);

            stopWatch2.Stop();

            Console.WriteLine("Recursive: " + r1 + " " + stopWatch1.ElapsedMilliseconds);
            Console.WriteLine("Iterative: " + r2 + " " + stopWatch2.ElapsedMilliseconds);
        }
Пример #7
0
        static void Main(string[] args)
        {
            f1 = new DelegateType(FibIter);
            f2 = new DelegateType(FibRec);
            f3 = new DelegateType(FacIter);
            f4 = new DelegateType(FacRec);

            IAsyncResult ar1 = f1.BeginInvoke(5, null, null);
            IAsyncResult ar2 = f2.BeginInvoke(5, null, null);
            IAsyncResult ar3 = f3.BeginInvoke(5, null, null);
            IAsyncResult ar4 = f4.BeginInvoke(5, null, null);

            int result1 = f1.EndInvoke(ar1);
            int result2 = f2.EndInvoke(ar2);
            int result3 = f3.EndInvoke(ar3);
            int result4 = f4.EndInvoke(ar4);


            Stopwatch sw = new Stopwatch();

            sw.Start();
            f1  = new DelegateType(FacIter);
            ar1 = f1.BeginInvoke(5, null, null);
            f2  = new DelegateType(FacRec);
            ar2 = f2.BeginInvoke(5, null, null);
            f3  = new DelegateType(FibIter);
            ar3 = f3.BeginInvoke(5, null, null);
            f4  = new DelegateType(FibRec);
            ar4 = f4.BeginInvoke(5, null, null);
            int najszybsze = WaitHandle.WaitAny(new WaitHandle[] { ar1.AsyncWaitHandle, ar2.AsyncWaitHandle, ar3.AsyncWaitHandle, ar4.AsyncWaitHandle });

            sw.Stop();
            Console.WriteLine("Najszybciej wykonalo sie:");
            switch (najszybsze)
            {
            case 0:
                Console.WriteLine("Fibbonaci Iteracyjnie");
                break;

            case 1:
                Console.WriteLine("Fibbonaci Rekurencyjnie");
                break;

            case 2:
                Console.WriteLine("Silnia Iteracyjnie");
                break;

            case 3:
                Console.WriteLine("Silnia Rekurencyjnie");
                break;
            }
            Console.WriteLine("W czasie: {0:00}:{1:00}:{2:000}", sw.Elapsed.Minutes, sw.Elapsed.Seconds, sw.Elapsed.Milliseconds);

            Console.ReadKey();
        }
Пример #8
0
        static void ThreadProc(IAsyncResult stateInfo)
        {
            DelegateType   delegat = ((object[])(stateInfo.AsyncState))[0] as DelegateType;
            string         info    = ((object[])(stateInfo.AsyncState))[1] as string;
            AutoResetEvent ev      = ((object[])(stateInfo.AsyncState))[2] as AutoResetEvent;

            var result = delegat.EndInvoke(stateInfo).ToString();

            Console.WriteLine(info + ": " + result);

            ev.Set();
        }
Пример #9
0
        static void Main(string[] args)
        {
            int liczba = 27;

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            dn = new DelegateType(silniaRekuren);
            IAsyncResult ar  = dn.BeginInvoke(liczba, null, null);
            int          res = dn.EndInvoke(ar);

            stopWatch.Stop();
            var ts = stopWatch.ElapsedMilliseconds;

            Console.WriteLine("Czas silni rekurencyjnie: " + ts + "ms");
            Console.WriteLine("Wynik: " + res);

            stopWatch.Restart();
            dn1 = new DelegateType(silniaIterac);
            IAsyncResult ar1  = dn1.BeginInvoke(liczba, null, null);
            int          res1 = dn1.EndInvoke(ar1);

            stopWatch.Stop();
            var ts2 = stopWatch.ElapsedMilliseconds;

            Console.WriteLine("Czas silni iteracyjnie: " + ts2 + "ms");
            Console.WriteLine("Wynik: " + res1);

            stopWatch.Restart();
            dn2 = new DelegateType(fibRek);
            IAsyncResult ar2  = dn2.BeginInvoke(liczba, null, null);
            int          res2 = dn2.EndInvoke(ar2);

            stopWatch.Stop();
            var ts3 = stopWatch.ElapsedMilliseconds;

            Console.WriteLine("Czas ciag fibbonacciego rekurencyjnie: " + ts3 + "ms");
            Console.WriteLine("Wynik: " + res2);

            stopWatch.Restart();
            dn3 = new DelegateType(fibIter);
            IAsyncResult ar3  = dn3.BeginInvoke(liczba, null, null);
            int          res3 = dn3.EndInvoke(ar3);

            stopWatch.Stop();
            var ts4 = stopWatch.ElapsedMilliseconds;

            Console.WriteLine("Czas ciag fibbonacciego iteracyjnie: " + ts4 + "ms");
            Console.WriteLine("Wynik: " + res3);


            Console.ReadKey();
        }
Пример #10
0
        static void Main(string[] args)
        {
            byte[] buffer = new byte[128];
            delegat = new DelegateType(Callback);
            IAsyncResult asyncResult = delegat.BeginInvoke(buffer, null, null);
            FileStream   fs          = new FileStream("C:\\Users\\user\\Desktop\\me\\FlorekIO\\FlorekIO\\IO\\zad6\\file.txt", FileMode.Open, FileAccess.Read);

            fs.Read(buffer, 0, buffer.Length);
            string result = delegat.EndInvoke(asyncResult);

            Console.WriteLine(Encoding.UTF8.GetString(buffer, 0, buffer.Length));
            fs.Close();
        }
Пример #11
0
Файл: z8.cs Проект: hobitolog/IO
        static void Main(string[] args)
        {
            delegateName  = new DelegateType(wypSilniaR);
            delegateName2 = new DelegateType(silniaI);
            delegateName3 = new DelegateType(wypFib);
            IAsyncResult ar     = delegateName.BeginInvoke(6, null, null);
            IAsyncResult ar2    = delegateName2.BeginInvoke(6, null, null);
            IAsyncResult ar3    = delegateName3.BeginInvoke(6, null, null);
            int          result = delegateName.EndInvoke(ar);

            int result2 = delegateName2.EndInvoke(ar2);

            int result3 = delegateName3.EndInvoke(ar3);
        }
Пример #12
0
        public void start()
        {
            Console.WriteLine("Silnia rekurencyjnie:");
            Int64     argu     = 25;
            Stopwatch ticktock = new Stopwatch();

            ticktock.Start();

            delegateName = new DelegateType(Silniarek);
            IAsyncResult ar1        = delegateName.BeginInvoke(argu, null, null);
            Int64        wsilniarek = delegateName.EndInvoke(ar1);

            Console.WriteLine(ticktock.Elapsed);
            Console.WriteLine("Wynik:");
            Console.WriteLine(wsilniarek);

            Console.WriteLine("Silnia iteracyjnie:");
            delegateName = new DelegateType(Silniaite);
            IAsyncResult ar2        = delegateName.BeginInvoke(argu, null, null);
            Int64        wsilniaite = delegateName.EndInvoke(ar2);

            Console.WriteLine(ticktock.Elapsed);

            Console.WriteLine("Wynik:");
            Console.WriteLine(wsilniaite);

            Console.WriteLine("Fibonacci rekurencyjnie:");

            delegateName = new DelegateType(Fiborek);
            IAsyncResult ar3      = delegateName.BeginInvoke(argu, null, null);
            Int64        wfiborek = delegateName.EndInvoke(ar3);

            Console.WriteLine(ticktock.Elapsed);
            Console.WriteLine("Wynik:");
            Console.WriteLine(wfiborek);

            Console.WriteLine("Fibonacci iteracyjnie:");


            delegateName = new DelegateType(Fiboite);
            IAsyncResult ar4      = delegateName.BeginInvoke(argu, null, null);
            Int64        wfiboite = delegateName.EndInvoke(ar4);

            Console.WriteLine(ticktock.Elapsed);

            Console.WriteLine("Wynik:");

            Console.WriteLine(wfiboite);
        }
Пример #13
0
        static void Main(string[] args)
        {
            int n = 5;

            iteracja = new DelegateType(iteracja);
            IAsyncResult z1 = iteracja.BeginInvoke(n, null, null);
            int          i  = iteracja.EndInvoke(z1);

            iteracja = new DelegateType(rekur);
            IAsyncResult z2  = iteracja.BeginInvoke(n, null, null);
            int          rek = iteracja.EndInvoke(z2);

            Console.WriteLine("Wynik iteracji: " + i);
            Console.WriteLine("Wynik rekurencji: " + rek);
        }
Пример #14
0
        /*
         * static void fibonacci_rec(IAsyncResult state)
         * {
         *  object[] obj = (object[])state.AsyncState;
         *  int res = (int)obj[1];
         *  int n = (int)obj[0];
         *  if ((n == 1) || (n == 2))
         *  {
         *      res = 1;
         *  }
         *  else
         *  {
         *      res = fibonacci_rec(n - 1) + fibonacci_rec(n - 2);
         *  }
         * }
         */

        static void zadanie8()
        {
            delegateType = new DelegateType(factorial_it2);
            IAsyncResult ar1     = delegateType.BeginInvoke(3, null, null);
            int          result1 = delegateType.EndInvoke(ar1);

            delegateType = new DelegateType(fibonacci_it2);
            IAsyncResult ar2     = delegateType.BeginInvoke(3, null, null);
            int          result2 = delegateType.EndInvoke(ar2);

            Console.WriteLine(result1);
            Console.WriteLine(result2);

            Console.ReadKey();
        }
Пример #15
0
        static void Main(string[] args)
        {
            delegateSilnia = new DelegateType(silnia);
            IAsyncResult ar     = delegateSilnia.BeginInvoke(5, new AsyncCallback(SCallback), null);
            int          result = delegateSilnia.EndInvoke(ar);

            delegateSilniaRek = new DelegateType(silniaRek);
            IAsyncResult arRek     = delegateSilniaRek.BeginInvoke(5, new AsyncCallback(SRekCallback), null);
            int          resultRek = delegateSilniaRek.EndInvoke(arRek);

            delegateFib = new DelegateType(fib);
            IAsyncResult arFib     = delegateFib.BeginInvoke(5, new AsyncCallback(FibCallback), null);
            int          resultFib = delegateFib.EndInvoke(arFib);

            Console.WriteLine("Silnia iteracyjnie: " + result);
            Console.WriteLine("Silnia rekurencyjnie: " + resultRek);
            Console.WriteLine("Fibonacci: " + resultFib);
        }
Пример #16
0
        static void Main(string[] args)
        {
            delegateSilniaIt  = new DelegateType(silniait);
            delegateSilniaRek = new DelegateType(silniarek);
            delegateFibo      = new DelegateType(fibo);

            IAsyncResult ar  = delegateSilniaIt.BeginInvoke(7, null, null);
            IAsyncResult ar2 = delegateSilniaRek.BeginInvoke(7, null, null);
            IAsyncResult ar3 = delegateFibo.BeginInvoke(7, null, null);

            int result1 = delegateSilniaIt.EndInvoke(ar);
            int result2 = delegateSilniaRek.EndInvoke(ar2);
            int result3 = delegateFibo.EndInvoke(ar3);

            //Console.WriteLine(result1);
            Console.WriteLine(result2);
            //Console.WriteLine(result3);
            Thread.Sleep(5000);
        }
        static void zadanie8()
        {
            delegatename = new DelegateType(silniaIt);
            IAsyncResult ar     = delegatename.BeginInvoke(20, null, null);
            int          result = delegatename.EndInvoke(ar);

            delegatename = new DelegateType(silniaRe);
            IAsyncResult ar2     = delegatename.BeginInvoke(8, null, null);
            int          result2 = delegatename.EndInvoke(ar2);

            delegatename = new DelegateType(fibRe);
            IAsyncResult ar3     = delegatename.BeginInvoke(8, null, null);
            int          result3 = delegatename.EndInvoke(ar3);

            Console.WriteLine("Silnia1: " + result);
            Console.WriteLine("Silnia2: " + result2);
            Console.WriteLine("Fibbonaci: " + result3);
            Console.ReadKey();
        }
Пример #18
0
        public Zad8()
        {
            var facRec  = new DelegateType(FacRec);
            var fibIter = new DelegateType(FibIter);
            var fibRec  = new DelegateType(FibRec);

            FacIter1 = FacIter;


            const int s            = 35;
            var       facRecResult = StopwatchUtil.Time(() =>
            {
                var result1 = facRec.BeginInvoke(s, null, null);
                facRec.EndInvoke(result1);
            });

            Console.WriteLine($"Czas obliczenia silni rekurencyjnie: {facRecResult}");

            var facIterResult = StopwatchUtil.Time(() =>
            {
                var result1 = FacIter1.BeginInvoke(s, null, null);
                FacIter1.EndInvoke(result1);
            });

            Console.WriteLine($"Czas obliczenia silni iteracyjnie {facIterResult}");

            var fibRecResult = StopwatchUtil.Time(() =>
            {
                var result1 = fibRec.BeginInvoke(s, null, null);
                fibRec.EndInvoke(result1);
            });

            Console.WriteLine($"Czas obliczenia ciągu fibonacciego rekurencyjnie {fibRecResult}");

            var fibIterResult = StopwatchUtil.Time(() =>
            {
                var result1 = fibIter.BeginInvoke(s, null, null);
                fibIter.EndInvoke(result1);
            });

            Console.WriteLine($"Czas obliczenia ciągu fibonacciego iteracyjnie {fibIterResult}");
        }
Пример #19
0
        static void Main(string[] args)
        {
            DelegateType D1 = new DelegateType(SilniaRekurencyjna);
            DelegateType D2 = new DelegateType(SilniaIteracyjna);
            DelegateType D3 = new DelegateType(Fibonacci);

            IAsyncResult IAR1 = D1.BeginInvoke(5, null, null);
            IAsyncResult IAR2 = D2.BeginInvoke(5, null, null);
            IAsyncResult IAR3 = D3.BeginInvoke(5, null, null);

            int wynik1 = D1.EndInvoke(IAR1);

            Console.WriteLine(wynik1);
            int wynik2 = D2.EndInvoke(IAR2);

            Console.WriteLine(wynik2);
            int wynik3 = D3.EndInvoke(IAR3);

            Console.WriteLine(wynik3);
        }
        static void Zadanie8()
        {
            Console.WriteLine("\n ///Zadanie 8/// \n");
            delegateName = new DelegateType(silniaI);
            IAsyncResult ar = delegateName.BeginInvoke(10, null, null);

            delegateName2 = new DelegateType(silniaR);
            IAsyncResult ar2 = delegateName2.BeginInvoke(10, null, null);

            delegateName3 = new DelegateType(fiboI);
            IAsyncResult ar3 = delegateName3.BeginInvoke(5, null, null);

            delegateName4 = new DelegateType(fiboR);
            IAsyncResult ar4 = delegateName4.BeginInvoke(5, null, null);

            Console.WriteLine("SilniaI " + delegateName.EndInvoke(ar));
            Console.WriteLine("SilniaR " + delegateName2.EndInvoke(ar2));
            Console.WriteLine("FiboI " + delegateName3.EndInvoke(ar3));
            Console.WriteLine("FiboR " + delegateName4.EndInvoke(ar4));
        }
Пример #21
0
        static void Main(string[] args)
        {
            silniaN   = new DelegateType(silniar);
            silnia    = new DelegateType(silniai);
            fibonaciN = new DelegateType(fibr);
            fibonaci  = new DelegateType(fibi);

            IAsyncResult ar     = silniaN.BeginInvoke(5, null, null);
            int          result = silniaN.EndInvoke(ar);

            IAsyncResult ar2     = fibonaciN.BeginInvoke(6, null, null);
            int          result2 = fibonaciN.EndInvoke(ar2);

            IAsyncResult ar3     = silnia.BeginInvoke(5, null, null);
            int          result3 = silnia.EndInvoke(ar3);

            IAsyncResult ar4     = fibonaci.BeginInvoke(6, null, null);
            int          result4 = fibonaci.EndInvoke(ar4);

            Console.WriteLine("5!={0}\nF(6)={1}", result, result2);
            Console.WriteLine("5!={0}\nF(6)={1}", result3, result4);
        }
Пример #22
0
        static void Zadanie8()
        {
            DelegateType recursiveFactorial = new DelegateType(RecursiveFactorial);
            var          ar = recursiveFactorial.BeginInvoke(10, null, null);

            Console.WriteLine("Recursive factorial: " + recursiveFactorial.EndInvoke(ar));

            DelegateType iterativeFactorial = new DelegateType(IterativeFactorial);
            var          ar2 = iterativeFactorial.BeginInvoke(10, null, null);

            Console.WriteLine("Iterative factorial: " + iterativeFactorial.EndInvoke(ar2));

            DelegateType recursivefib = new DelegateType(RecursiveFib);
            var          ar3          = recursivefib.BeginInvoke(10, null, null);

            Console.WriteLine("Recursive fibonacci: " + recursivefib.EndInvoke(ar3));

            DelegateType interativefib = new DelegateType(IterativeFib);
            var          ar4           = interativefib.BeginInvoke(10, null, null);

            Console.WriteLine("Interative fibonacci: " + interativefib.EndInvoke(ar4));
        }
Пример #23
0
        static void Main(string[] args)
        {
            silnia_rek_del    = new DelegateType(Silnia_rek);
            silnia_ite_del    = new DelegateType(Silnia_ite);
            fibonacci_ite_del = new DelegateType(Fibonacci_ite);
            fibonacci_rek_del = new DelegateType(Fibonacci_rek);

            IAsyncResult iasyncResult1 = silnia_rek_del.BeginInvoke(5, null, null);
            IAsyncResult iasyncResult2 = silnia_ite_del.BeginInvoke(5, null, null);
            IAsyncResult iasyncResult3 = fibonacci_ite_del.BeginInvoke(5, null, null);
            IAsyncResult iasyncResult4 = fibonacci_rek_del.BeginInvoke(5, null, null);

            int result1 = silnia_rek_del.EndInvoke(iasyncResult1);
            int result2 = silnia_ite_del.EndInvoke(iasyncResult2);
            int result3 = fibonacci_ite_del.EndInvoke(iasyncResult3);
            int result4 = fibonacci_rek_del.EndInvoke(iasyncResult4);

            Console.WriteLine(result1);
            Console.WriteLine(result2);
            Console.WriteLine(result3);
            Console.WriteLine(result4);
            Console.ReadKey();
        }
Пример #24
0
        public Zad8()
        {
            //Dla silnie podmienić na funkcje silnii
            delegat1 = new DelegateType(fib);

            delegat2 = new DelegateType(fibRek);

            int value = 21;

            IAsyncResult result = delegat1.BeginInvoke(value, null, null);

            IAsyncResult resultRek = delegat2.BeginInvoke(value, null, null);

            int delegateResultRek = delegat2.EndInvoke(resultRek);

            Console.WriteLine("Rekurencyjnie: " + delegateResultRek);

            //Z racji, że EndInvoke jest blokowy, wynik dla funkcji iteracyjnej wyświetlany przed zwróceniem jej wyniku.
            //Może to delikatnie przekłamać wynik, ale przy większych liczbach nie zrobi to większej różnicy.
            int delegateResult = delegat1.EndInvoke(result);

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            delegate_silniaRek = new DelegateType(SilniaRek);
            IAsyncResult iar_silRek       = delegate_silniaRek.BeginInvoke(10, new AsyncCallback(SilniaRekCallback), null);
            int          wynik_silnia_rek = delegate_silniaRek.EndInvoke(iar_silRek);

            delegate_silniaIt = new DelegateType(SilniaIt);
            IAsyncResult iar_silIt       = delegate_silniaIt.BeginInvoke(10, new AsyncCallback(SilniaItCallback), null);
            int          wynik_silnia_it = delegate_silniaIt.EndInvoke(iar_silIt);

            delegate_fibbonaciRek = new DelegateType(FibbonaciRek);
            IAsyncResult iar_fibbonaciRek   = delegate_fibbonaciRek.BeginInvoke(20, new AsyncCallback(FibbonaciRekCallback), null);
            int          wynik_fibbonaciRek = delegate_fibbonaciRek.EndInvoke(iar_fibbonaciRek);

            delegate_fibbonaciIt = new DelegateType(FibbonaciIt);
            IAsyncResult iar_fibbonaciIt   = delegate_fibbonaciIt.BeginInvoke(20, new AsyncCallback(FibbonaciItCallback), null);
            int          wynik_fibbonaciIt = delegate_fibbonaciIt.EndInvoke(iar_fibbonaciIt);

            Console.WriteLine("Wynik rekurencyjnie obliczonej silni: " + wynik_silnia_rek);
            Console.WriteLine("Wynik iteracyjnie obliczonej silni: " + wynik_silnia_it);
            Console.WriteLine("Wartosc 20 elementu ciagu fibbonaciego (rekurencyjnie): " + wynik_fibbonaciRek);
            Console.WriteLine("Wartosc 20 elementu ciagu fibbonaciego (iteracyjnie): " + wynik_fibbonaciIt);
            Console.ReadKey();
        }