winform只允许一个应用程序运行

使用互斥体Mutex类型

using System.Threading;

//声明互斥体
Mutex mutex = new Mutex(false, "ThisShouldOnlyRunOnce");
//判断互斥体是否使用中
bool Running = !mutex.WaitOne(0, false);
if (!Running)
     Application.Run(new Form1());
else
      MessageBox.Show("应用程序已经启动!");
posted @ 2013-10-24 15:26  yuejin  阅读(385)  评论(0编辑  收藏  举报