dtrz17917 2014-10-02 13:58
浏览 41
已采纳

如何使用c#.net检查运行特定脚本的php进程是否正在运行

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

  • 写回答

1条回答 默认 最新

  • dreamact3026 2014-10-02 14:04
    关注

    Set a variable (e.g. a boolean) before starting the process and unset it when the process exits.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理