Process

G

Guest

I am using the following code to see if a process is currently running. I
want to do something if it is NOT running. I am having trouble testing the
array when no process is runing. Null won't work. Any ideas?

// is process currently running in case someone closed it manually
Process[] myProcesses;
// Returns array containing all instances of EcpKpScript_01.exe
myProcesses = Process.GetProcessesByName("EcpKpScript_01");

myProcesses in debug mode shows "{dimensions[0]}". If this helps.
Thanks
 
P

pgpalmer

int procCount = 0;
Process[] myProcesses = Process.GetProcesses();
try
{
foreach(Process proc in myProcesses)
{
if (proc.ProcessName==myprocessname)
procCount = procCount + 1;
}
}
catch
{
}

if (procCount <= 1)
{
MessageBox.Show("It ain't running.");
}
 
P

pgpalmer

int procCount = 0;
Process[] myProcesses = Process.GetProcesses();
try
{
foreach(Process proc in
myProcesses)
{
if
(proc.ProcessName==myprocessname)
procCount =
procCount + 1;
}
}
catch
{
}

if (procCount ==0) // CORRECTED HERE
{
MessageBox.Show("It ain't running.");
}

int procCount = 0;
Process[] myProcesses = Process.GetProcesses();
try
{
foreach(Process proc in myProcesses)
{
if (proc.ProcessName==myprocessname)
procCount = procCount + 1;
}
}
catch
{
}

if (procCount <= 1)
{
MessageBox.Show("It ain't running.");
}

I am using the following code to see if a process is currently running. I
want to do something if it is NOT running. I am having trouble testing the
array when no process is runing. Null won't work. Any ideas?
// is process currently running in case someone closed it manually
Process[] myProcesses;
// Returns array containing all instances of EcpKpScript_01.exe
myProcesses = Process.GetProcessesByName("EcpKpScript_01");
myProcesses in debug mode shows "{dimensions[0]}". If this helps.
Thanks
 

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