PC Review


Reply
Thread Tools Rate Thread

Detecting that a program is already running

 
 
Joecx
Guest
Posts: n/a
 
      26th Aug 2004
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
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      26th Aug 2004
* (E-Mail Removed) (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/>
 
Reply With Quote
 
Matt S
Guest
Posts: n/a
 
      26th Aug 2004
You could try something like...

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

Hope this helps.

"Joecx" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      26th Aug 2004
Herfried

For you to change

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


:-)

Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      26th Aug 2004
* "Cor Ligthert" <(E-Mail Removed)> 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/>
 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      26th Aug 2004
* "Matt S" <(E-Mail Removed)> scripsit:
> You could try something like...
>
> -- Code starts --
> If
> Process.GetProcessesByName(Process.GetCurrentProcess().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/>
 
Reply With Quote
 
Matt S
Guest
Posts: n/a
 
      26th Aug 2004
Good point. Noted.

Matt.

"Herfried K. Wagner [MVP]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> * "Matt S" <(E-Mail Removed)> scripsit:
> > You could try something like...
> >
> > -- Code starts --
> > If
> >

Process.GetProcessesByName(Process.GetCurrentProcess().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/>



 
Reply With Quote
 
Josip Medved
Guest
Posts: n/a
 
      27th Aug 2004

> -- Code starts --
> If
> Process.GetProcessesByName(Process.GetCurrentProcess().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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting which Windows is running avi Microsoft Excel Programming 8 15th Jun 2008 08:28 PM
detecting a running program on pocketpc from desktop code Sai Microsoft Dot NET Compact Framework 2 19th Jan 2005 08:40 PM
Detecting that a program is already running Joecx Microsoft Dot NET 6 5th Sep 2004 09:37 PM
Detecting Running Applications PeterM Microsoft Access Form Coding 2 23rd Apr 2004 06:38 PM
Detecting if running in VS.NET ko Microsoft Dot NET Framework 4 11th Sep 2003 10:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:46 AM.