关于限制一个程序只能运行一个实例,实现方法如下,当然,还有很多种方法。
(详细请参考MSDN中对Mutex类的说明)
using System.Threading;
static void Main()
{
bool initiallyOwned = true;
bool isCreated;
Mutex m = new Mutex(initiallyOwned,"MyTest",out isCreated);
if (!(initiallyOwned && isCreated))
{
MessageBox.Show("抱歉,程序只能在一台机上运行一个实例!","提示");
Application.Exit();
}
else
{
Application.Run(new MainForm());
}
}