Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if an application is blocked/busy?

I'm trying to automate the GUI of an external application using C#/.NET 4.0

The application that's being automated (AUT) is a VB6 app.

When doing an action, or clicking a button, the AUT sometimes spends a lot of time waiting for the DB to respond. When the app is waiting for the DB results, the app itself is idle (doesn't register much CPU usage), but it's blocked (you can't click or interact with it).

-So far, I've tried looking at the mouse pointer (hourglass) as an indicator, but sometimes the app is blocked but cursor is normal. So this isn't reliable.

-I've tried looking at the main process of the AUT for TotalProcessorTime (this measures if the app is IDLE or BUSY), but like I said, sometimes the app is IDLE, and still blocked.

So i'd like to tape into the stackOverflow crowd's experience to see if anyone already knows how to handle that, and/or if you have any ideas on how to achieve this.

Thanks

EDIT:

I've been playing around, and just discovered something.

While the AUT is blocked, it isn't responding to keyboard or mouse input. However, if I send WM_LBUTTONCLICK messages to the window, I can confirm that the messages are being processed (and the UI changes).

So I'm guessing that they are purposefully blocking the app while making DB calls.

like image 484
DanyO Avatar asked Jul 15 '11 22:07

DanyO


1 Answers

You can check whether or not the UI of that application is responding:

Get the process instance for that application and check its Responding property. like:

//To get the process instance
Process  application = null;
foreach (var process in Process.GetProcesses())
{
    if (process.ProcessName == "The Process Name")
    {
        application = process;
        break;
    }
}

//to check if the process UI is not responding
if (application.Responding)
{ 
    //
}

Edit: You can modify the timeout used by application.Responding check this.

like image 111
Jalal Said Avatar answered Oct 23 '22 13:10

Jalal Said