[STAThread]
static void Main() // args are OK here, of course
{
bool ok;
m = new System.Threading.Mutex(true, "YourNameHere", out ok);
static void Main() // args are OK here, of course
{
bool ok;
m = new System.Threading.Mutex(true, "YourNameHere", out ok);
if (! ok)
{
MessageBox.Show("Another instance is already running.");
return;
}
Application.Run(new Form1()); // or whatever was there
GC.KeepAlive(m); // important!
}
博客展示了一段代码,代码中先判断条件是否满足,若不满足则弹出提示框并返回;若满足则运行指定窗体,同时还调用了GC.KeepAlive方法。

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



