check if a apllication is already running?

  • Thread starter Thread starter jam
  • Start date Start date
J

jam

Dear all

Process [] checkpro = Process.GetProcessesByName("abc");
Console.WriteLine(checkpro [0]);

correct ma?? how should i do??

jam
 
Hi Jam,

// 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.
 
Thx a lot!~!!!
Champika Nirosh said:
Hi Jam,

// 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.

jam said:
Dear all

Process [] checkpro = Process.GetProcessesByName("abc");
Console.WriteLine(checkpro [0]);

correct ma?? how should i do??

jam
 
Hi Jam,

// 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());

I think that using Mutex will be much more appropriate here (at least in
order to prevent your application being started twice).

Michal Dabrowski
 
Back
Top