Preventing multiple instances of an app - with a flourish

P

Patrick B

Here is the code I use to stop a user from starting multiple instances
of my application:

mutex = new Mutex(true, "MyMutex", out onlyInstance);
if (! onlyInstance) { return; }

This code works. If the user starts my program, and then tries to start
it a second time, the second instance will detect that it's not the only
instance, and it will shut down.

I'd like to improve this, though...

I'd like the second instance to somehow notify the first instance to
call a method. So if the user tries to start the application a second
time, the first instance of the application can respond with a series of
actions (like making a log entry, restoring the main form if it's
minimized, etc).

Any ideas for ways to do that?

Thanks!

-Patrick
 
C

Chris Taylor

Hi,

You could use remoting, the first instance starts up and publishes a
remoting end point. If a second instance is started it connects to the
endpoint on the first instance and invokes a method that performs the tasks
you require.

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

Top