好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

C#使用Mutex简单实现程序单实例运行的方法

本文实例讲述了C#使用Mutex简单实现程序单实例运行的方法。分享给大家供大家参考。具体如下:

[STAThread] static void Main() {

  bool isAppRunning = false ;

  System.Threading.Mutex mutex = new System.Threading.Mutex( true ,System.Diagnostics.Process.GetCurrentProcess().ProcessName, out isAppRunning);

  if (!isAppRunning) {

   MessageBox.Show( "本程序已经在运行了,请不要重复运行!" );

   Environment.Exit(1);

  }

  else

  {

   Application.EnableVisualStyles();

   Application.SetCompatibleTextRenderingDefault( false );

   Application.Run( new Form1());

  }

}

希望本文所述对大家的C#程序设计有所帮助。

dy("nrwz");

查看更多关于C#使用Mutex简单实现程序单实例运行的方法的详细内容...

  阅读:78次