如何检查应用程序是否已在运行? [英] how to check if app is already running?

查看:87
本文介绍了如何检查应用程序是否已在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


我想避免在同一台计算机上两次启动相同的c#应用程序。

我如何检查它是否是已经在运行了吗?


谢谢

Hi all

I''d like to avoid starting the same c# application twice on the same computer.
How do I check if it is already running?

Thank you

推荐答案

private void Test_Launcb()

{

Process [] localByName = Process.GetProcessesByName(" ProgramName"); //

其中ProgramName是你的应用程序的名称


if(localByName.Length 1)//这个副本是1

{


Application.Exit();


}


}


希望这会有所帮助

Dan

" Alex K." < Al *** @ discussion.microsoft.com写信息

news:14 ************************* ********* @ microsof t.com ...
private void Test_Launcb()

{
Process [] localByName = Process.GetProcessesByName("ProgramName"); //
Where ProgramName is the name of your Application

if (localByName.Length 1) // This copy makes 1

{

Application.Exit();

}

}


Hope this helps
Dan
"Alex K." <Al***@discussions.microsoft.comwrote in message
news:14**********************************@microsof t.com...

大家好


我''我想避免在相同的

计算机上两次启动相同的c#应用程序。

如何检查它是否已经运行?


谢谢
Hi all

I''d like to avoid starting the same c# application twice on the same
computer.
How do I check if it is already running?

Thank you



Alex,


这是对不同帖子的回复它回答了你的问题:

http://groups.google.com/group/micro...128f9ddd957ada

希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv * @ spam.guard.caspershouse.com


" Alex K." < Al *** @ discussion.microsoft.com写信息

news:14 ************************* ********* @ microsof t.com ...
Alex,

Here is a response to a different post which answers your question:

http://groups.google.com/group/micro...128f9ddd957ada

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alex K." <Al***@discussions.microsoft.comwrote in message
news:14**********************************@microsof t.com...

大家好


我''我想避免在相同的

计算机上两次启动相同的c#应用程序。

如何检查它是否已经运行?


谢谢
Hi all

I''d like to avoid starting the same c# application twice on the same
computer.
How do I check if it is already running?

Thank you



Hello Dan,


考虑到这个没有在终端服务部门工作。在这种情况下

u需要使用Global Mutex


DTprivate void Test_Launcb()

DT>

DT {

DT>

DTProcess [] localByName = Process.GetProcessesByName(" ProgramName");

DT //其中ProgramName是申请名称

DT>

DTif(localByName.Length 1)//此副本生成1

DT>

DT {

DT>

DTApplication.Exit();

DT>

DT}

DT>

DT}

DT>

DTHope这有帮助

DTDan

DT" Alex K." < Al *** @ discussion.microsoft.com写信息

DTnews:14 ************************* ********* @ micros oft.com ...

DT>
Hello Dan,

Take into account that this doesn''t work in Terminal Services. In that case
u need to use Global Mutex

DTprivate void Test_Launcb()
DT>
DT{
DT>
DTProcess [] localByName = Process.GetProcessesByName("ProgramName");
DT// Where ProgramName is the name of your Application
DT>
DTif (localByName.Length 1) // This copy makes 1
DT>
DT{
DT>
DTApplication.Exit();
DT>
DT}
DT>
DT}
DT>
DTHope this helps
DTDan
DT"Alex K." <Al***@discussions.microsoft.comwrote in message
DTnews:14**********************************@micros oft.com...
DT>

>大家好

我想避免两次启动相同的c#应用程序相同的
电脑。
如何检查它是否已经在运行?
谢谢
>Hi all

I''d like to avoid starting the same c# application twice on the same
computer.
How do I check if it is already running?
Thank you



- -

WBR,

Michael Nemtsev ::博客: http://spaces.live.com/laflour


有时一个人仍然忠于某一事业只是因为其对手没有

不再是平淡的。 (c)Friedrich Nietzsche

---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


这篇关于如何检查应用程序是否已在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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