Esempio n. 1
0
        public static void Main()
        {
            SumCalculator sumCalculator = new SumCalculator();
            var           first         = new Thread(() => { sumCalculator.Calculate(1, 495, null); });
            var           second        = new Thread(() => { sumCalculator.Calculate(495, 500, null); });

            Console.WriteLine(result);
            Console.ReadLine();
        }
        public static void Main()
        {
            ManualResetEvent manualResetEvent = new ManualResetEvent(false);
            SumCalculator    sumCalculator    = new SumCalculator();
            var first  = new Thread(() => { sumCalculator.Calculate(1, 495, null); });
            var second = new Thread(() => { sumCalculator.Calculate(495, 500, manualResetEvent); });

            first.Start();
            second.Start();
            first.Join();
            manualResetEvent.Set();
            second.Join();
            manualResetEvent.Dispose();
            Console.WriteLine(result);
            Console.ReadLine();
        }