问题描述
我用c#制作了一个gui程序但是我想要即使人们多次点击我的
程序,它也只会打开一次
就是这样的可能它是怎么回事?
I made a gui program with c# but i want even if people double click my
program more than once it would only open once
is something like that possible if it is how?
推荐答案
我已经用过这个课了,工作得很好..这是在vb.net,我希望这是
不是问题...
使用全局互斥锁识别正在运行的实例。
这样可以防止在机器范围内运行多个实例。
bool freeToRun;
string safeName =" Global \\StringUniquelyIdentifyingThisApplication" ;
使用(System.Threading.Mutex m = new System.Threading.Mutex(true,safeName
,out freeToRun))
{
if(freeToRun)
Application.Run(new MainForm());
MessageBox.Show("已经在运行......) ;,safeName);
}
威利。
Use a global mutex to identify your running instance.
This way you prevent running multiple instances machine wide.
bool freeToRun;
string safeName = "Global\\StringUniquelyIdentifyingThisApplication" ;
using(System.Threading.Mutex m = new System.Threading.Mutex(true, safeName
, out freeToRun))
{
if (freeToRun)
Application.Run (new MainForm());
MessageBox.Show("Already running...", safeName);
}
Willy.
这篇关于防止两次打开程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!