One instance only

A

Aaron

I created a simple exe program in c#. I would like to run one instance of
the program at a time. if i click the exe after the program is already
opened it should NOT start a new instance of the program it should set focus
to the currently running program.

Thanks
Aaron
 
T

Trebek

Use the Process class to examine running processes to determine if your app
is running ...

HTH,

Alex
 
L

Lawrence Oluyede

Aaron said:
I created a simple exe program in c#. I would like to run one instance of
the program at a time. if i click the exe after the program is already
opened it should NOT start a new instance of the program it should set focus
to the currently running program.

using System.Threading;

public class blah
{
public static void main(string[] args)
{
// the first instance of this program will
// create a mutex and its waitone returns
// true so, the other instances will get false
Mutex mutex = new Mutex(false, "blah");
if(mutex.WaitOne(1, false) == false)
return;
}
}
 

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