예제 #1
0
        // Run this example in 'Debug' mode
        // Run this example in 'Release' mode
        // Notice the differences in the execution workflow
        // In 'Debug' mode, the compiler does not optimize the code and the potential problem is not revealed
        // However, In 'Release' mode, the compiler optimizes the code and the problem is revealed
        public static void Main(string[] args)
        {
            var shared = new SharedControlClass();
            shared.IsRunning = true;

            var thread = new Thread(DoControlledWork);
            thread.Start(shared);

            // Sleep for 1 second to allow the new thread to begin execution
            Thread.Sleep(1000);

            // Change the value of 'IsRunning' to false
            // In order to interrupt the 'while' loop in the new thread
            shared.IsRunning = false;
            Console.WriteLine("Value of 'isRunning' set to false");
        }
예제 #2
0
        // Run this example in 'Debug' mode
        // Run this example in 'Release' mode
        // Notice the differences in the execution workflow
        // In 'Debug' mode, the compiler does not optimize the code and the potential problem is not revealed
        // However, In 'Release' mode, the compiler optimizes the code and the problem is revealed
        public static void Main(string[] args)
        {
            var shared = new SharedControlClass();

            shared.IsRunning = true;

            var thread = new Thread(DoControlledWork);

            thread.Start(shared);

            // Sleep for 1 second to allow the new thread to begin execution
            Thread.Sleep(1000);

            // Change the value of 'IsRunning' to false
            // In order to interrupt the 'while' loop in the new thread
            shared.IsRunning = false;
            Console.WriteLine("Value of 'isRunning' set to false");
        }