How to prevent open my application more than one time? [duplicate]

半城伤御伤魂 提交于 2019-12-12 15:56:09

问题


Possible Duplicate:
What is the correct way to create a single instance application?

How can I define my application to open only one time after click on its exe file over and over?


回答1:


I've always done this at the application's entry point:

bool onlyInstance = false;

Mutex m = new Mutex(true, "MyUniqueMutextName", out onlyInstance);
if (!onlyInstance)
{
    return;
}

GC.KeepAlive(m);



回答2:


There are several related questions on Stack Overflow for Single Instance Applications:

This one seems to be the most apropriate: What is the correct way to create a single-instance application?



来源:https://stackoverflow.com/questions/9719653/how-to-prevent-open-my-application-more-than-one-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!