One instance only

  • Thread starter Thread starter Aaron
  • Start date Start date
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
 
Use the Process class to examine running processes to determine if your app
is running ...

HTH,

Alex
 
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;
}
}
 
Back
Top