Sign in to follow this  
Followers 0
qwert

How to determine when an application is really ready?

14 posts in this topic

I use an au3 script to adjust the window of a database application after it has initialized. Since that initialization includes the application's own window size/position settings, I have to wait until it is fully initialized before issuing my window commands.

I've tried using a WinWaitActive step -- even followed by a 2 second pause -- to determine when to initiate the Set Style commands. The problem is that the application takes a different amount of time to initialize, mostly depending on the current runtime environment of the PC (e.g., how many applications are already running).

Is there another way to test that an application is "ready" -- or "idle"? If not, what is a recommended way to pass a signal from a startup script inside the database application?

Any suggestions will be appreciated.

Share this post


Link to post
Share on other sites



Thanks for the response. Your function looks like a great foundation for building task management capability into a script, but it's somewhat beyond my level of au3 capability at this point. I've tried to follow the code to determine a way to check for status = idle, but I can't see it. Is there a single WMI call that can be fashioned to only return the status for a single PID?

Or, since my need is rather simple, would it be better to have the application launch a "drone task" when initialization is complete -- and then have my main script use a ProcessWait to pause until it runs? (BTW, my main script is the one that starts the database application.)

Share this post


Link to post
Share on other sites

Thanks for the response. Your function looks like a great foundation for building task management capability into a script, but it's somewhat beyond my level of au3 capability at this point. I've tried to follow the code to determine a way to check for status = idle, but I can't see it. Is there a single WMI call that can be fashioned to only return the status for a single PID?

Or, since my need is rather simple, would it be better to have the application launch a "drone task" when initialization is complete -- and then have my main script use a ProcessWait to pause until it runs? (BTW, my main script is the one that starts the database application.)

You don't have to figure out the internals of the function to use it. The function _ProcessListProperties() returns a 2D array listing properties of matching processes (figure out how another day). If you specify the PID or name of the process you are interested in, you get only results for that process, but still in a 2D array. The CPU usage would be in the returned array at [1][6]. Assuming CPU usage of 0 for that process over 3 consecutive seconds is a sufficient test of "idleness", the test would look like this:

$sDir = "C:\Program Files\Your\Program\Here"
$sEXE = $sDir & "\Executable.exe"

; Run your program
$PID = Run($sEXE, $sDir)

; Loop untill CPU usage is 0 for three consecutive seconds
$iCnt = 0
Do
    Sleep(1000)
    $avProps = _ProcessListProperties($PID)
    If $avProps[0][0] <> 0 Then
        If $avProps[1][6] = 0 Then
            $iCnt += 1
        Else
            $iCnt = 0
        EndIf
    Else
        MsgBox(16, "Error", "Error!  PID " & $PID & " doesn't exist.")
        Exit
    EndIf
Until $iCnt = 3

MsgBox(64, "Idle", "PID " & $PID & " has been idle for at least 3 consecutive seconds.")

You need to include the function declaration from _ProcessListProperties(), just copy/paste that into your script.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

The example you provided makes everything clear (re: monitoring CPU usage). I can see that using the entire function makes sense in this instance, since it is somewhat involved. Usually, when I only need to make one call (ever) to a function, I look for a way to fashion a script step or two to perform only the part of the function that I need -- which helps keep my own script simple and understandable. That's what led me to the question in my response.

Anyway, thanks very much for your help on this.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Or maybe you can retrieve a text in the Statusbar of the window that shows 'ready' or something like that !?

Greetz

Greenhorn

Edited by Greenhorn

Share this post


Link to post
Share on other sites

...and then there are the pixel functions - perhaps PixelCheckSum.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

You don't have to figure out the internals of the function to use it. The function _ProcessListProperties() returns a 2D array listing properties of matching processes (figure out how another day). If you specify the PID or name of the process you are interested in, you get only results for that process, but still in a 2D array. The CPU usage would be in the returned array at [1][6]. Assuming CPU usage of 0 for that process over 3 consecutive seconds is a sufficient test of "idleness", the test would look like this:

$sDir = "C:\Program Files\Your\Program\Here"
$sEXE = $sDir & "\Executable.exe"

; Run your program
$PID = Run($sEXE, $sDir)

; Loop untill CPU usage is 0 for three consecutive seconds
$iCnt = 0
Do
    Sleep(1000)
    $avProps = _ProcessListProperties($PID)
    If $avProps[0][0] <> 0 Then
        If $avProps[1][6] = 0 Then
            $iCnt += 1
        Else
            $iCnt = 0
        EndIf
    Else
        MsgBox(16, "Error", "Error!  PID " & $PID & " doesn't exist.")
        Exit
    EndIf
Until $iCnt = 3

MsgBox(64, "Idle", "PID " & $PID & " has been idle for at least 3 consecutive seconds.")

You need to include the function declaration from _ProcessListProperties(), just copy/paste that into your script.

:)

I hate to reply to an old post but this reference is exactly what I'm looking for. I've tried this sample code but everytime I try it, I get a window with the entire list of processes. I used Notepad.exe is my Executable.exe and I'm also getting the follow errors:

C:\Program Files\AutoIt3\Include\_ProcessListProperties.au3 (63) : ==> The requested action with this object has failed.:

If $oProc.GetOwner($sUserName, $sUserDomain) = 0 Then $avProcs[$n][3] = $sUserDomain & "\" & $sUserName

If $oProc.GetOwner($sUserName, $sUserDomain) ^ ERROR

Share this post


Link to post
Share on other sites

I hate to reply to an old post but this reference is exactly what I'm looking for. I've tried this sample code but everytime I try it, I get a window with the entire list of processes. I used Notepad.exe is my Executable.exe and I'm also getting the follow errors:

C:\Program Files\AutoIt3\Include\_ProcessListProperties.au3 (63) : ==> The requested action with this object has failed.:

If $oProc.GetOwner($sUserName, $sUserDomain) = 0 Then $avProcs[$n][3] = $sUserDomain & "\" & $sUserName

If $oProc.GetOwner($sUserName, $sUserDomain) ^ ERROR

Actually, you found a serious bug in _ProcessListProperties(). I had removed ProcessList() from inside the function, and the way I did it broke the ability to find processes by PID or name.

The patched version is v2.0.2 dated 07/02/2008. The function was moved to its own topic in Example Scripts. Get _ProcessListProperties() here from now on.

Thanks for reporting your issue.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Actually, you found a serious bug in _ProcessListProperties(). I had removed ProcessList() from inside the function, and the way I did it broke the ability to find processes by PID or name.

The patched version is v2.0.2 dated 07/02/2008. The function was moved to its own topic in Example Scripts. Get _ProcessListProperties() here from now on.

Thanks for reporting your issue.

:)

The error is gone but the window titled "%avRet" is still coming up with the entire list of processes. After I close that window I get my MsgBox with the CPU usage. Is there something I'm missing to suppress that dialog with the entire list?

CODE
#include <_ProcessListProperties.au3>

$stats = _ProcessListProperties("application.exe")

MsgBox(0, "App CPU Usage usage",Number($stats[1][6]))

Thanks for your help

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

The error is gone but the window titled "%avRet" is still coming up with the entire list of processes. After I close that window I get my MsgBox with the CPU usage. Is there something I'm missing to suppress that dialog with the entire list?

CODE
#include <_ProcessListProperties.au3>

$stats = _ProcessListProperties("application.exe")

MsgBox(0, "App CPU Usage usage",Number($stats[1][6]))

Thanks for your help
:P

I strongly suspect you copied the little demo script into your "_ProcessListProperties.au3" UDF, and not just the function...

...I'm just glad I've never made such a silly mistake!

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

:(

I strongly suspect you copied the little demo script into your "_ProcessListProperties.au3" UDF, and not just the function...

...I'm just glad I've never made such a silly mistake!

muttley

Doh! :)

Thanks

Share this post


Link to post
Share on other sites

Doh! :)

Thanks

This is just what I've been looking for too - just stumbled on it - thanks for PSaltyDS. However, I'm getting this error:

C:\BATCH\AutoIt scripts\process_list_properties.au3 (129) : ==> The requested action with this object has failed.:

$colProcs = $oRefresher.AddEnum($oWMI, "Win32_PerfFormattedData_PerfProc_Process" ).objectSet

$colProcs = $oRefresher.AddEnum($oWMI, "Win32_PerfFormattedData_PerfProc_Process" )^ ERROR

I'm just running it using the demo calls under XP with admin privs. Thoughts on what might be causing it would be gladly received.

Share this post


Link to post
Share on other sites

This is just what I've been looking for too - just stumbled on it - thanks for PSaltyDS. However, I'm getting this error:

C:\BATCH\AutoIt scripts\process_list_properties.au3 (129) : ==> The requested action with this object has failed.:

$colProcs = $oRefresher.AddEnum($oWMI, "Win32_PerfFormattedData_PerfProc_Process" ).objectSet

$colProcs = $oRefresher.AddEnum($oWMI, "Win32_PerfFormattedData_PerfProc_Process" )^ ERROR

I'm just running it using the demo calls under XP with admin privs. Thoughts on what might be causing it would be gladly received.

Just running the demo in the first post of the example topic? That's odd.

Add a COM Error handler (in the help file under "OBJ/COM Reference") to see if more useful info turns up. Actually, there should always be one in any script that uses COM interfaces anyway, so I added it to the demo in the example scripts topic, too.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0