By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

Detecting that a program is already running

P: n/a
Hi
Does anyone have the code or maybe give me a start on how to detect if my
program is already running if someone tries to run it again while it's already
running? I know I could do this with a dummy file by putting something in the
file while it's running and emptying the file when it's not running, but I was
hoping for something a little more professional. Has anyone done this yet?

Joe
Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
* jo***@aol.com (Joecx) scripsit:
Does anyone have the code or maybe give me a start on how to detect if my
program is already running if someone tries to run it again while it's already
running?


<URL:http://www.pobox.com/~skeet/csharp/faq/#one.application.instance>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2

P: n/a
You could try something like...

-- Code starts --
If
Process.GetProcessesByName(Process.GetCurrentProce ss().ProcessName).Length >
0 Then
' exit application or display message
End If
-- Code ends --

Hope this helps.

"Joecx" <jo***@aol.com> wrote in message
news:20***************************@mb-m21.aol.com...
Hi
Does anyone have the code or maybe give me a start on how to detect if my
program is already running if someone tries to run it again while it's already running? I know I could do this with a dummy file by putting something in the file while it's running and emptying the file when it's not running, but I was hoping for something a little more professional. Has anyone done this yet?
Joe

Nov 21 '05 #3

P: n/a
Herfried

For you to change

http://www.yoda.arachsys.com/csharp/...ation.instance
:-)

Cor
Nov 21 '05 #4

P: n/a
* "Cor Ligthert" <no**********@planet.nl> scripsit:
For you to change

http://www.yoda.arachsys.com/csharp/...ation.instance


This one works too, and I think it's the preferred one. Thanks for
making me aware of that.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5

P: n/a
* "Matt S" <ma**@toomuchspamalready.com> scripsit:
You could try something like...

-- Code starts --
If
Process.GetProcessesByName(Process.GetCurrentProce ss().ProcessName).Length >
0 Then
' exit application or display message
End If


Notice that the application name isn't necessarily unique.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6

P: n/a
Good point. Noted.

Matt.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uC*************@TK2MSFTNGP10.phx.gbl...
* "Matt S" <ma**@toomuchspamalready.com> scripsit:
You could try something like...

-- Code starts --
If
Process.GetProcessesByName(Process.GetCurrentProce ss().ProcessName).Length > 0 Then
' exit application or display message
End If


Notice that the application name isn't necessarily unique.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7

P: n/a
-- Code starts --
If
Process.GetProcessesByName(Process.GetCurrentProce ss().ProcessName).Length
> 0 Then

' exit application or display message
End If
-- Code ends --


Note that this code will detect it self. It should stand .Length > 1.
BTW ProcessName is not necessary unique.

--
Pozdrav,
Josip Medved, MCSD
http://www.jmedved.com
Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.