class Program
    {
    
        private volatile bool paused; 
        private ManualResetEvent resumeEvent = new ManualResetEvent(false);
        private static bool Running = true;

        void MyThread()
        {
            for (int i = 0; i < 100; i++) 
            {
                if (paused) 
                {
                    resumeEvent.WaitOne(); 
                } 
                DoTest();
            } 
        } 

        void Pause() 
        {
            resumeEvent.Reset();
            paused = true;
        } 

        void Resume()
        {
            paused = false; 
            resumeEvent.Set(); 
        }

        static void Main(string[] args)
        {
            Thread[] threads = new Thread[3];
            for (int i = 0; i < 3; i++)
            {
                threads[i].Start();
            }
        }
        
        private static void DoTest()
        {
            while (Running)
            {
                Thread.Sleep(1000);
            }
        }
      }
posted on 2013-09-10 17:28  xiaowy  阅读(307)  评论(0编辑  收藏  举报