话不多说,直接上代码:
static void Main()
{
System.Threading.Mutex mutex = new System.Threading.Mutex(false, "命名空间");
bool running = !mutex.WaitOne(0, false);
if (!running)
Application.Run(new FrmLogin());//FrmLogin为主窗体名
else
MessageBox.Show("程序已运行!");
}
用到了Mutex类;Mutex类详细解析:https://msdn.microsoft.com/zh-cn/library/system.threading.mutex.aspx