I have a .net application that can execute a php script..
private const string PROGRAM_CALL = @"php.exe";
private const string PROGRAM_PARAMETERS = @"scriptA.php scriptA.cnf";
The following code is executed in the constructor of a class:
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(PROGRAM_CALL)
{
UseShellExecute = false,
WorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
RedirectStandardOutput = true,
Arguments = PROGRAM_PARAMETERS
};
_process.EnableRaisingEvents = true;
_process.Exited += new EventHandler(Process_Exited);
_process.StartInfo = myProcessStartInfo;
Then as required the process is started. It can be started by different calls.. Currently this start statement is in a method that is called from numerous places.
_process.Start();
What I'd like to figure out is if the php script is already running?
What I've tried so far is:
bool isRunning = Process.GetProcessesByName(_process.ProcessName).Length > 0;
However on debug I can see that _process.ProcessName throws an exception (InvalidOperationException)
Kind Regards, Fiona