线程同步 进程同步 static EventWaitHandle eHandle = new EventWaitHandle(false, EventResetMode.AutoReset,"LLLLL");
这个名字LLLLL取相同就能让同一台电脑上两个进程同步
主动控制程序
class Program
    {
       static  EventWaitHandle eHandle = new
        EventWaitHandle(false, EventResetMode.AutoReset,"LLLLL");
        static void Main(string[] args)
        {
            Console.WriteLine("主动控制");
            Thread.Sleep(3000);
            Start();
            Thread.Sleep(3000);
            Start();
            Thread.Sleep(3000);
            Start();
            Thread.Sleep(3000);
            Start();
            Thread.Sleep(3000);
            Start();
        }
        static bool Start()
        {
            return eHandle.Set();
        }
    }

 

被动控制进程程序:
class Program
    {
        static EventWaitHandle eHandle = new
         EventWaitHandle(false, EventResetMode.AutoReset, "LLLLL");
        static void Main(string[] args)
        {
            Console.WriteLine("被控制");
            Thread th = new Thread(DoMethod); 
            th.Start();
            Start();

            // Start();

            //Stop();
            //Start();
            Stop();
            
            Console.ReadKey();
            
        }
        static bool Stop()
        {
           return  eHandle.WaitOne();
        }
        static bool Start()
        {
             return eHandle.Set();
        }
        static void DoMethod()
        {   
            while (true)
            {
                Stop();
                    Console.WriteLine(" running");
                    System.Threading.Thread.Sleep(1000);
            }
        }
    }