I am simulating a console window in my project. I use the Process
class to run a console application, and I use a TextBox
for the user to interact with the console application. I wish to make the TextBox
enabled only when the process is waiting for user input.
However I could find no way to do that. Here is a similar question: Is my process waiting for input? But the solution to that question does not work for me. I have tried
foreach (ProcessThread thread in process.Threads)
if (thread.ThreadState == ThreadState.Wait)
{
// see what thread.WaitReason is
}
But thread.WaitReason
always give ThreadWaitReason.Executive
, both when the process is busy and when it is waiting for input.
Now my alternative solution is to parse the output, since the console application prints a string of a certain pattern every time it needs an input. But that's not a good solution, since there might be mistakes, and it may fail with other console applications, if the output is very difficult to parse, or not parsable at all.
So, is there a way to detect whether the process is waiting for input?