Jump to content

sleep program until a process is complete


 Share

Recommended Posts

Hi,

I am trying to close a window after it is done calculating.
I have no idea how to check what AutoIT is able to read from the window. So i don't know what variable i could put at the parameter 'text' from the function WinWaitActive.

So far i have tried these options:

WinWaitActive("MatchID 2D","")
MouseClick("left",43,703,1) ;clicks on the cross
;(when i do this, it instantly clicks on the close button after the window opens)

WinWaitActive("MatchID 2D","Close")
MouseClick("left",43,703,1) ;clicks on the cross
;(when i do this, the program never closes the window and the autoIT script keeps running)

WinWaitActive("MatchID 2D","Close")
MouseClick("left",43,703,1) ;clicks on the cross
;(when i do this, the program never closes the window and the autoIT script keeps running, just like the previous try)

I have attached print screens of what the window looks like before it is done calculating and after.

 

I hope someone can help me
(if you recuire more info, please respond and i shall provide if i can)

 

Greetings Theo

Start-Correlation.PNG

End-Correlation.PNG

Link to comment
Share on other sites

 

2 minutes ago, Earthshine said:

read the help file for Process functions. loop until you don't find it anymore. that's how to do it

https://www.autoitscript.com/autoit3/docs/functions/ProcessExists.htm

Thank you for your quick response.

I have thought about this aswel. But the process that this calculation uses is MatchID.exe
And this process keeps running even after the calculation is complete

Link to comment
Share on other sites

1 minute ago, Earthshine said:

you can look for visual indicators then with imagesearch maybe, or text on the form that indicates it is done. Look for the word Subset for instance. that happens when it's done, right?

if i wanna look for the wordt 'subset', do i do this by using this function:

WinWaitActive("MatchID 2D","Subset")

Or am i doing something wrong ?

Link to comment
Share on other sites

hey, check this out. I was thinking, you can monitor the Match app cpu usage and see when it drops to idle. call:

Func _ProcessGetCPU($strProcess = "Idle", $iSampleTime = 500, $sComputerName = @ComputerName)

 

NOTE, when  you run this, it pops up an icon in your system tray that tells you the cpu usage and such, but you can just comment out that stuff. I can help you.

$array = ProcessList("MatchID 2D.exe")
$iPID = $array[1][1]
$sProcess = $iPID           ;PID number for test process name

;~ $sProcess = "Idle"       ;Other test process names
;~ $sProcess = "_Total"     ;funny one
;~ $sProcess = "ntvdm"      ;DOS process
;~ $sProcess = "AutoIt3"    ;do not assign .exe to process name


While 1
    
    $iProcessCPU = _ProcessGetCPU($sProcess, 300 )

    $sTip = "Process " & $sProcess & " CPU: " & $iProcessCPU & "%"
    traytip("", $sTip   ,1)
;~  sleep(1000)     ;set your own sleep time for LOOP mode
WEnd


Func _ProcessGetCPU($strProcess = "Idle", $iSampleTime = 500, $sComputerName = @ComputerName)
    
;~      All Parameters are optional:
;~          - Idle process will be measured if first parameter is not set
;~          - 500 ms is default sample time
;~          - This computer will be measured by default
;~      Process could be string ("Name") or PID number (1234)
;~      When more processes are runing with identical name, then the last opened is measured (use PID for other)
;~      For NORMAL MODE(one time measuring): set Sample value to more than 0 ms
;~                  ( average CPU usage will be measured during sleep time within function)
;~      For LOOP MODE (continuous measuring): set Sample value to 0 ms
;~                  ( average CPU usage will be measured between two function calls )
;~      Total CPU usage is: ( 100 - _ProcessGetCPU())
;~      Success: Returns process CPU usage in percent
;~              (Sample times below 100ms may return inaccurate results)
;~              (First result in Loop Mode may be inaccurate,
;~               because first call in Loop Mode is only used to trigger counters)
;~      Failure: Returns -1  ( wrong process name or PID )
;~             : Returns -2  ( WMI service not found or Computer not found)

    if $strProcess = "" then $strProcess = "Idle"
    if $iSampleTime = "" AND IsString($iSampleTime) then $iSampleTime = 500
    if $sComputerName = "" then $sComputerName = @ComputerName
    
    if not IsDeclared("iP1") AND $iSampleTime = 0 then      ;first time in loop mode
        $bFirstTimeInLoopMode = 1
    else
        $bFirstTimeInLoopMode = 0
    endif
    
    if not IsDeclared("iP1") then
        assign("iP1", 0, 2)     ;forced global declaration first time
        assign("iT1", 0, 2)
    endif
    
    
    $objWMIService = ObjGet("winmgmts:\\" & $sComputerName & "\root\CIMV2")
    if @error then return -2
    
    if number($strProcess) then 
        $strProcess = " WHERE IDProcess = '" & $strProcess & "'"
    else 
        $strProcess = " WHERE Name = '" & $strProcess & "'"
    endif

    if $iSampleTime OR $bFirstTimeInLoopMode = 1 then   ;skip if Loop Mode, but not First time
        
        $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PerfRawData_PerfProc_Process" & $strProcess)
        
        For $objItem In $colItems
            
            $iT1 = $objItem.TimeStamp_Sys100NS
            $iP1 = $objItem.PercentProcessorTime
        next

        if  $objItem = "" then return -1    ;process not found
        
        sleep($iSampleTime)
    endif
    
        
    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PerfRawData_PerfProc_Process" & $strProcess)

    For $objItem In $colItems
                    
        $iP2 = $objItem.PercentProcessorTime
        $iT2 = $objItem.TimeStamp_Sys100NS  
    next

    if  $objItem = "" then return -1    ;process not found
        
    $iPP = ($iP2 - $iP1)
    $iTT = ($iT2 - $iT1)
    
    if $iTT = 0 Then return 100     ;do not divide by 0

    $iCPU = round( ($iPP/$iTT) * 100, 0)
    
    $iP1 = $iP2
    $iT1 = $iT2
    Return $iCPU
EndFunc ;==>_ProcessGetCPU() by novaTek    ...ver 0.11

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

tank you for the reply !!

Sorry about my late answer, i was looking into the ImageSearch function and having a lot of problems with it ..

But monitoring the CPU does seem like a better option!

I wasn't sure how to implement the function into my script.
So i copy pasted the script of the function itself ( everything from "Func" to "EndFunc") at the start of my script and added this into my script:
(see attached picture)

It seems to work
So thank you very much !!! @Earthshine

 

SUCCESS.PNG

Edited by Theodoor
Link to comment
Share on other sites

it is always best to lead your questions with all your code, or at least something we can test with, of course along with rich details and whatnot. glad you got it working!

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

ok so i ran into another problem.

As you can see on the screenshot i used:

local $iPID = 7252

but obviously the Process ID changes after reboot.
So i tried your suggested method :

Local $aArray = ProcessList("MatchID 2D.exe")
Local $iPID = $aArray[1][1]
Local $sProcess = $iPID

But when i run the script, i get this error (attached prt scrn)

I looked up the function ProcessList and i can't seem to find anything that i am doing wrong.

AutoIT error.PNG

Link to comment
Share on other sites

you get that error because it does not find your process. were you not running MatchID?

$array = ProcessList("'MatchID 2D.exe'")
If @error Then MsgBox($MB_OK, "Error Finding Process", @error)
$iPID = $array[1][1]
$sProcess = $iPID           ;PID number for test process name

;~ $sProcess = "Idle"       ;Other test process names
;~ $sProcess = "_Total"     ;funny one
;~ $sProcess = "ntvdm"      ;DOS process
;~ $sProcess = "AutoIt3"    ;do not assign .exe to process name


$iProcessCPU = _ProcessGetCPU($sProcess, 300 )

$sTip = "Process " & $sProcess & " CPU: " & $iProcessCPU & "%"
traytip("", $sTip   ,1)
sleep(1000)     ;set your own sleep time for LOOP mode
Send( $iProcessCPU )

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...