關(guān)于限制一個(gè)程序只能運(yùn)行一個(gè)實(shí)例,實(shí)現(xiàn)方法如下,當(dāng)然,還有很多種方法。
(詳細(xì)請(qǐng)參考MSDN中對(duì)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("抱歉,程序只能在一臺(tái)機(jī)上運(yùn)行一個(gè)實(shí)例!","提示");
Application.Exit();
}
else
{
Application.Run(new MainForm());
}
}