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);
            }
        }
      }

相关文章:

  • 2021-12-12
  • 2021-12-27
  • 2021-12-22
  • 2021-10-12
  • 2021-08-09
  • 2021-12-12
  • 2021-10-05
  • 2022-12-23
猜你喜欢
  • 2021-12-12
  • 2021-12-12
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2021-12-12
相关资源
相似解决方案