C# 用ManulResetEvent 控制Thread的 Suspend、Resume

class Program
    {
        static void Main(string[] args)
        {
            Thread thread = new Thread(Work);
            thread.Start();

            Console.ReadLine();
            Pause();
            Console.ReadLine();
            Resume();
            Console.ReadLine();
            
            Pause();
            Console.ReadLine();
            Resume();
        }

        static ManualResetEvent wait_handle = new ManualResetEvent(true);

        

        static void Pause()
        {

            wait_handle.Reset();
        }

        static void Resume()
        {
            wait_handle.Set();
        }

        static private void Work()
        {
            while(true)
            {
                
                wait_handle.WaitOne();

                Console.WriteLine("running...");
            }
        }
    }

 

posted @ 2018-01-30 10:12  akiing  阅读(301)  评论(0编辑  收藏  举报