Stop two instances of a C# app running

  • Thread starter Thread starter Bishman
  • Start date Start date
B

Bishman

I am sure this question has been asked many times before but can someone
suggest a method of stopping two instances of a C# app running at the same
time ?

Preferably I would like an attempt to invoke a second instance to bring the
first instance to the top.

Thanks.

Jon.
 
Bishman said:
I am sure this question has been asked many times before but can someone
suggest a method of stopping two instances of a C# app running at the same
time ?

You can create named Mutex object in the app instance and then check with
other instances of the program if that mutex is created. If there is no
mutex - then the application is the first, otherwise it is other instance
( 2-nd ).
Preferably I would like an attempt to invoke a second instance to bring
the first instance to the top.

After second instance got knew that there is already an instance of the app
running it can search for its window ( maybe via win32 FindWindow(...) ),
bring that window to front and then finish execution.
 
This is boilerplate! Can't we make this a project setting and be done with
it?

-Eric
 

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