Is my process waiting for input?

前端 未结 3 1627

I am using the Process class to run an exe.

The exe is a 3rd party console application that I do not control.

I wish to know whether the process is waiting f

3条回答
  •  盖世英雄少女心
    2020-12-05 06:01

    Depending on what the 3rd party process is doing exactly you could try polling its threads' states:

    foreach(ProcessThread thread in process.Threads)
        if (thread.ThreadState == ThreadState.Wait
            && thread.WaitReason == ThreadWaitReason.UserRequest)
                process.Kill();
    

    Failing that... you can try to

    process.StandardInput.Close();
    

    after calling Start(), I conjecture that an exception will be raised in the child process if it's trying to read from standard input.

提交回复
热议问题