How to check multiple instances of an application..?

  • Thread starter Thread starter kiran
  • Start date Start date
K

kiran

How can I check whether a application is laready running in the current
system...?

I want to check when the application is in "hidden" state. first instance
window style is "Hide" . When ever user trying to open a second or new
instance .it should detect the first instance automatically and first
instance should be activate and show to the user.( it can be any state
normal, minimize or maximize )

Regards
kiran
 
Enum processes using System.Diagnostics.Process.GetProcessByName
see more in MSDN
Vit
 
kiran,

Juval Lowy created a neat little utility class which handles this. You
can download it from (watch for line wrap):

http://www.idesign.net/idesign/uploads/Singleton.zip

Basically, it uses a mutex to see if another app instance is open. If
it is, it uses remoting to send a message to that application, and show it.

This functionality is available in .NET as well. In .NET 2.0, you can
use the WindowsApplicationBase class in the
Microsoft.VisualBasic.ApplicationServices namespace to handle this
functionality for you. There is a question in the ".NET Matters" section of
the September issue of MSDN magazine that shows how to do this. You can
find it online at (watch for line wrap):

http://msdn.microsoft.com/msdnmag/issues/05/09/NETMatters/

Specifically, it is the second question.

Hope this helps.
 
This is actually a VERY bad idea. Enumerating through all of the
available processes can be quite intensive, and there are better ways to do
it.

Check my response for some of those ways.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top