如何限制程序只能运行一个实例。 [英] How to limit program can only run one instance.

查看:75
本文介绍了如何限制程序只能运行一个实例。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


如何限制c#程序只能在同一时间运行一个实例

时间?


谢谢!


祝你好运,

Boki。

Hi All,

How to limit the c# program can only run one instance at the same
time ?

Thank you!

Best regards,
Boki.

推荐答案

" Boki Digtal" < bo ****** @ ms21.hinet.net写了留言新闻:11 ********************* @ x35g2000prf.googlegro ups.com .. 。
"Boki Digtal" <bo******@ms21.hinet.netwrote in message news:11*********************@x35g2000prf.googlegro ups.com...

如何限制c#程序只能在同一个

时间内运行一个实例?
How to limit the c# program can only run one instance at the same
time ?



使用System.Threading;


bool blnFirstInstance;


使用( Mutex objMutex = new Mutex(false,Local\\"" app name>",out blnFirstInstance))

{

if (!blnFirstInstance)

{

MessageBox.Show("< app nameis already running",Single Use Only,MessageBoxButtons.OK,MessageBoxIcon.Stop) ;

Application.Exit();

}

else

{

Application.Run(new Form1()); //或者你的创业公司......

}

}

-

Mark Rae

ASP.NET MVP
http://www.markrae.net


On 7 23,6 11,Mark Rae [MVP]" < m ... @ markNOSPAMrae.netwrote:
On 7 23 , 6 11 , "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:

" Boki Digtal" < bokit ... @ ms21.hinet.netwrote in messagenews:11 ********************* @ x35g2000prf.go oglegroups.com ...
"Boki Digtal" <bokit...@ms21.hinet.netwrote in messagenews:11*********************@x35g2000prf.go oglegroups.com...

如何限制c#程序只能在同一个

时间内运行一个实例?
How to limit the c# program can only run one instance at the same
time ?



使用System.Threading;


bool blnFirstInstance;


使用( Mutex objMutex = new Mutex(false,Local\\"" app name>",out blnFirstInstance))

{

if (!blnFirstInstance)

{

MessageBox.Show("< app nameis already running",Single Use Only,MessageBoxButtons.OK,MessageBoxIcon.Stop) ;

Application.Exit();

}

else

{

Application.Run(new Form1()); //或者你的创业公司......

}


}


-

Mark Rae

ASP.NET MVPhttp://www.markrae.net


using System.Threading;

bool blnFirstInstance;

using (Mutex objMutex = new Mutex(false, "Local\\" + "<app name>", out blnFirstInstance))
{
if (!blnFirstInstance)
{
MessageBox.Show("<app nameis already running", "Single Use Only", MessageBoxButtons.OK, MessageBoxIcon.Stop);
Application.Exit();
}
else
{
Application.Run(new Form1()); // or whatever your startup is...
}

}

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net



太棒了,谢谢!


Boki。

Great, thanks!

Boki.


7月24日,2月27日,Boki Digtal< bokit ... @ ms21.hinet.netwrote :
On 7 24 , 2 27 , Boki Digtal <bokit...@ms21.hinet.netwrote:

7月23日,6月11日,Mark Rae [MVP]" < m ... @ markNOSPAMrae.netwrote:
On 7 23 , 6 11 , "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:

" Boki Digtal" < bokit ... @ ms21.hinet.netwrote in messagenews:11 ********************* @ x35g2000prf.go oglegroups.com ...
"Boki Digtal" <bokit...@ms21.hinet.netwrote in messagenews:11*********************@x35g2000prf.go oglegroups.com...

如何限制c#程序只能在同一个

时间内运行一个实例?
How to limit the c# program can only run one instance at the same
time ?


使用System.Threading;
using System.Threading;


bool blnFirstInstance;
bool blnFirstInstance;


using(Mutex objMutex = new Mutex(false,Local\\" +"< app name>", out blnFirstInstance))

{

if(!blnFirstInstance)

{

MessageBox.Show("< ; app nameis已经在运行",Single Use Only,MessageBoxButtons.OK,MessageBoxIcon.Stop);

Application.Exit();

}

else

{

Application.Run(new Form1()); //或者你的创业公司......

}
using (Mutex objMutex = new Mutex(false, "Local\\" + "<app name>", out blnFirstInstance))
{
if (!blnFirstInstance)
{
MessageBox.Show("<app nameis already running", "Single Use Only", MessageBoxButtons.OK, MessageBoxIcon.Stop);
Application.Exit();
}
else
{
Application.Run(new Form1()); // or whatever your startup is...
}


}
}


-

Mark Rae

ASP.NET MVPhttp://www.markrae.net
--
Mark Rae
ASP.NET MVPhttp://www.markrae.net



太棒了,谢谢!


Boki。


Great, thanks!

Boki.



有没有像OnlyOneInstance = ture更简单的方法;


谢谢:)


Boki。

Is there any easier way like OnlyOneInstance = ture;

Thanks :)

Boki.


这篇关于如何限制程序只能运行一个实例。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆