I've written a simple windows app with one form. It's purpose is to run only in one instance. I used the mutex approach and throw a message when a second instance tries to run. Now I would like to change this message box and I only want to bring the first Instance to the top when trying to fire a second instance. My code is currently:
namespace WindowsFormsApplication2
{
static class Program
{
[STAThread]
static void Main()
{
bool mutexCreated = false;
System.Threading.Mutex mutex = new System.Threading.Mutex(true,@"Local\WindowsFormsApplication2.WindowsFormsApplication2.exe", out mutexCreated);
if(!mutexCreated )
{
if( MessageBox.Show("The application is already running.Hit the OK to exit", "",MessageBoxButtons.OK, MessageBoxIcon.Information ) != DialogResult.Cancel )
{
mutex.Close();
return;
}
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}