[STAThread]
static void Main()
{
bool createdNew = false;
Mutex mutex = new Mutex(true, “CSharpHowTo_SingleInstanceApp”,
out createdNew);
if (createdNew)
{
//没有运行实例
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
else
{
MessageBox.Show( “You can only run a single instance of this app!”);
}
}
本文介绍了一种在C#中实现单实例应用程序的方法,通过使用Mutex确保同一时刻仅有一个应用实例运行。

被折叠的 条评论
为什么被折叠?



