Check if previous instance of application exists

  • Thread starter Thread starter Hubert Hermanutz
  • Start date Start date
H

Hubert Hermanutz

Hi,

is it possible with C#/.NET looking after previous instances of application,
or rather to check if previous instance is always running?

Thanks in advance,
Hubert
 
Hi,

static void Main()
{
// get the name of our process
string proc=Process.GetCurrentProcess().ProcessName;
// get the list of all processes by that name
Process[] processes=Process.GetProcessesByName(proc);
// if there is more than one process...
if (processes.Length > 1)
{
MessageBox.Show("Application is already running");
return;
} else
Application.Run(new Form1());
}

Nirosh
 
Hi Nirosh,

thank you, it works.

Regards,
Hubert



Champika Nirosh said:
Hi,

static void Main()
{
// get the name of our process
string proc=Process.GetCurrentProcess().ProcessName;
// get the list of all processes by that name
Process[] processes=Process.GetProcessesByName(proc);
// if there is more than one process...
if (processes.Length > 1)
{
MessageBox.Show("Application is already running");
return;
} else
Application.Run(new Form1());
}

Nirosh

Hubert Hermanutz said:
Hi,

is it possible with C#/.NET looking after previous instances of application,
or rather to check if previous instance is always running?

Thanks in advance,
Hubert
 
Back
Top