Second instance of app referencing first instance of app?

  • Thread starter Thread starter Jon Pope
  • Start date Start date
J

Jon Pope

I've got an application that uses a Mutex to prevent multiple instances of
the application from launching. This works great for me.

However, what I would like to do is when a second attempt to launch the
application is detected, it activates the first instance then closes the
second instance. At app startup, how can I grab a reference to another
instance of my app so that I can signal to it to activate itself?

Cheers, Jon
 
Jon,

If you are using .NET 1.1 and before, then you will have to set up a
remoting server on the app that is running, and it needs to use a well known
address. Then, in the second app, it would make a call to the first one,
and activate it.

In .NET 2.0, look at the WindowsFormsApplicationBase class in the
Microsoft.VisualBasic namespace. You can derive a class from that, and then
set the protected IsSingleInstance property to true. It will cause only one
instance of your app to run. Additionally, when the second instance is
started, it will cause the StartupNextInstance method on the running app to
fire, at which point, you can handle that event and have it do something.

Hope this helps.
 

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