示例#1
0
        static void Main()
        {
            const int threadCount = 10;

            ManualResetEvent[]         finishEvents = new ManualResetEvent[threadCount];
            FibonacciCalculatorClass[] numberArr    = new FibonacciCalculatorClass[threadCount];
            Random r = new Random();

            Console.WriteLine("Запуск операции подсчета...");
            for (int i = 0; i < threadCount; i++)
            {
                finishEvents[i] = new ManualResetEvent(false);
                FibonacciCalculatorClass f = new FibonacciCalculatorClass(r.Next(10, 20), finishEvents[i]);
                numberArr[i] = f;
                ThreadPool.QueueUserWorkItem(f.CallBackMethod);
            }

            WaitHandle.WaitAll(finishEvents);
            Console.WriteLine("Вычисления закончены");

            for (int i = 0; i < threadCount; i++)
            {
                FibonacciCalculatorClass f = numberArr[i];
                Console.WriteLine("{0}-е число Фибоначчи = {1}", f.Number, f.Result);
            }
        }
示例#2
0
        static void Main()
        {
            const int threadCount = 10;

            ManualResetEvent[] finishEvents = new ManualResetEvent[threadCount];
            FibonacciCalculatorClass[] numberArr = new FibonacciCalculatorClass[threadCount];
            Random r = new Random();

            Console.WriteLine("Запуск операции подсчета...");
            for (int i = 0; i < threadCount; i++)
            {
                finishEvents[i] = new ManualResetEvent(false);
                FibonacciCalculatorClass f = new FibonacciCalculatorClass(r.Next(10, 20), finishEvents[i]);
                numberArr[i] = f;
                ThreadPool.QueueUserWorkItem(f.CallBackMethod);
            }

            WaitHandle.WaitAll(finishEvents);
            Console.WriteLine("Вычисления закончены");

            for (int i = 0; i < threadCount; i++)
            {
                FibonacciCalculatorClass f = numberArr[i];
                Console.WriteLine("{0}-е число Фибоначчи = {1}", f.Number, f.Result);
            }
        }