private void MainWindow_Load(object sender, System.EventArgs e)
{

    Process[] processes=Process.GetProcessesByName("MYEXENAME");
      if( processes != null)
     {
    if( (processes.Length)== 2)  //第2个进程
    {
       processes[1].CloseMainWindow();

      }
   }
}

STAThread]
        static void Main(string[] args)
        {
            //保证该程序只有一个在运行
            bool createdNew;
            System.Threading.Mutex mutex_Application = new System.Threading.Mutex(true,"test",out createdNew);
            if (!createdNew)
            {
                MessageBox.Show("本程序只允许同时运行一个!");
                return;
            }
        
            Application.Run();
            
        }        

相关文章:

  • 2021-11-02
  • 2021-12-18
  • 2021-12-18
  • 2021-07-26
  • 2021-11-30
  • 2022-12-23
  • 2022-01-24
猜你喜欢
  • 2021-12-08
  • 2021-12-29
  • 2021-12-18
  • 2021-12-18
  • 2021-11-26
  • 2022-12-23
相关资源
相似解决方案