The difference between c # tell you in plain English and Join the Thread of Sleep

Our program defaults have two threads, one is the main thread, a thread is responsible for garbage collection. If the code does not use multiple threads, the main thread only this one road.
1. Call Thread.Sleep in the main thread (1000), represents the main thread to block their own 1 second.
2. Use the main thread thread of the call Join () method, represents the main thread you tell the child thread needs to block for a while, until I complete the task.
Although both are blocking the main thread, however, is a main thread blocks its own, the other is the child thread block the main thread.

        private void Test()
        {
            Thread.Sleep ( 1000 ); // main thread blocking one second here

            var thread = new Thread(new ThreadStart(() =>
            {
                // simulation performed three seconds 
            }));
            thread.Start();
            Thread.join (); // main thread 3 seconds Here blocked 
        }

 

Guess you like

Origin www.cnblogs.com/subendong/p/11776100.html