限制程序重复执行
 private void MainWindow_Load(object sender, System.EventArgs e)
private void MainWindow_Load(object sender, System.EventArgs e)  {
{ 
 Process[] processes=Process.GetProcessesByName("MYEXENAME");
    Process[] processes=Process.GetProcessesByName("MYEXENAME");  if( processes != null)
      if( processes != null)  {
     {  if( (processes.Length)== 2)  //第2个进程
    if( (processes.Length)== 2)  //第2个进程  {
    {  processes[1].CloseMainWindow();
       processes[1].CloseMainWindow(); 
 }
      }  }
   }  }
} 


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

 
                    
                

 
      
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号