I'm using automation to test an application, but sometimes I want to start the application via a batch file. When I run "process.WaitForInputIdle(100)" I get an error:
"WaitForInputIdle failed. This could be because the process does not have a graphical interface."
How can I tell if the process has a graphical interface or not?
There are some standards as to how one should use a Graphical User Interface. The Visibility and abstraction must be uniform, at least with GUI developed from a single company. Each and every GUI has its own features and functions, but the graphic elements and terminology of the system and its architecture must be well maintained.
GUI means Graphical User Interface. It is the common user Interface that includes Graphical representation like buttons and icons, and communication can be performed by interacting with these icons rather than the usual text-based or command-based communication.
If an interface isn’t built with its users in mind, no one will be able to find the information they need when they need it, nor will they remember where anything is. It’s like being caught in a rainstorm and not being able to open your umbrella.
Files, programs, web pages etc. can be represented using a small picture in a graphical user interface. This picture is known as an icon. Using an icon is a fast way to open documents, run programs etc. because clicking on them yields instant access.
You can simply try and catch the exception:
Process process = ...
try
{
process.WaitForInputIdle(100);
}
catch (InvalidOperationException ex)
{
// no graphical interface
}
I was think along the lines of this, Still ugly but trys to avoid exceptions.
Process process = ...
bool hasUI = false;
if (!process.HasExited)
{
try
{
hasUI = process.MainWindowHandle != IntPtr.Zero;
}
catch (InvalidOperationException)
{
if (!process.HasExited)
throw;
}
}
if (!process.HasExited && hasUI)
{
try
{
process.WaitForInputIdle(100);
}
catch (InvalidOperationException)
{
if (!process.HasExited)
throw;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With