SorryButImaNewbie

waiting for window for to long (time out 500+?)

31 posts in this topic

Hello!

In a program my company uses, there is a "query" (hope this is the right word, used google translate, I mean when you ask "down" information from a database) which counts and summ up a good chunk of data, the problem is that it takes time, like more then 2 minutes usually (and usually during this the program become unresponsive), my question is, how do you guys handle a situation like this? Should I just use a WinWaitActive with a timeout like 500? (just to be sure, some times it loads for 5 min sometimes for 3) That would be my go to plan, but what if it would actually work out, but timeout runs out? I would just have to restart it again. Of course I would like to handle it in a way that my code can't get stuck/frozen waiting for something that will never happen (like without a timeout)

Any suggestion?

Share this post


Link to post
Share on other sites



So a 3rd party program queries a database and you do not know in advance how long it will run?

If the query has finished your AutoIt script will do something with the result?

Can you manually determine if the database query is still running? Let's say a counter in the status line of the 3rd party program or something like this?

How do you determine that the query has finished? Does a new window appear?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I can't (more precisly I dont know how to) determine if the query is running or not, I can only send the query (push the button) and hope for the best. I know if its succesfully ran by a window appering with the datas

Edit: Ohh and the what i do with the datas, thats the fun part... actually nothing, the script will just test the program (and its succesiv updates) so I only make a prtscrn of it.... ( its actually not written down in the specification, but i will ask the responsible guy about it tomorrow, since it only asks me to open it...)

Edit2: The 5 minutes was truthfully a tip, I used a stopwatch, 8:47 was the first time :)

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

You could create a GUI with a "Cancel" button so the user can end your script any time.

To check for the window use AdLibRegister to call a function every x seconds and use WinExists to check for the window. If the window was found, unregister the function and set a flag. In the main script you then can act on this flag and take the screenshot.

Sounds a bit cryptic?

If yes, I can provide an example.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Actually to my suprise, no, I understand  :D I never used AdLibRegister before, but I'm sure I can handle it, register and unregister it when window pop (if its do). Do you think its a good idea, to use maybe a MsgBox to maybe make the user able to end the script? ((since I built my GUI with ISN Studio, and I'm not sure how to add other windows yet) and use its return to abort and return to the idling state (maybe close the unrespansive window and re-open the program it works with)

Thanks for the advice Master Water :)

Edited for funny parenthesis, they still are, i use them to much

Edit2: wiat MsgBox would stop the script, but the script actually doesn't work but just wait, can i somehow close my own msgbox from the script if specific windw pops up?

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Here is the example. You simply need to change the title for Notepad.

#include <GUIConstantsEx.au3>
Global $bWindowFound = False
Global $sTitle = "Unbenannt - Editor" ; Example: Title of the Notepad Window
AdlibRegister("_CheckWindow", 1000) ; Check for the Window every second
GUICreate('Test', 600, 400, -1, -1)
$BTN = GUICtrlCreateButton("Exit", 10, 10, 80, 30)
GUISetState(@SW_SHOW)
While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $BTN
            Exit
    EndSwitch
    If $bWindowFound Then
        MsgBox(0, "Test", "Window found")
        Exit
    EndIf

WEnd

Func _CheckWindow()
    If WinExists($sTitle) Then
        $bWindowFound = True
        AdlibUnRegister("_CheckWindow")
    EndIf
EndFunc   ;==>_CheckWindow

Edit:
Should be AdlibUnRegister in function _CheckWindow().

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

It is AdlibUnRegister in function _CheckWindow().

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Guys, I seems to be stuck with Master Water's solution, I'm pretty sure I'm only inches away from salvation otherwise :), maybe I miss a function call of _Checkwindow or something

Func UD_informaciok() 

    If Not WinExists("UD Operátor") Then
        MsgBox(0, "Üzenet", "Kérem nyissa meg az UD_OPER programot!", 10)
        Return
    EndIf
    ControlClick("UD Operátor", "", "[CLASSNN:TAdvBitBtn6]")
    WinWaitActive("Dátum beállítás", "", 5)
    ControlClick("Dátum beállítás", "", "[CLASSNN:TBitBtn1]") ;> Things i start the query with

    AdlibRegister("_CheckWindow", 1000)
    $TesztStopGUI = GUICreate('Test', 100, 50, -1, -1)
    $BTN = GUICtrlCreateButton("Exit", 10, 10, 80, 30)

    GUISetState(@SW_SHOW)
    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $BTN
                Return Alapjarat()
GUIDelete($TesztStopGUI)
            Case GUISetOnEvent($GUI_EVENT_CLOSE, "Alapjarat") ;>I want the button to return to idle, I think i may miss something on the line, that its not correctly linked to the $BTN (use ISN Studio generally for GUI)
Return Alapjarat()
                GUIDelete($TesztStopGUI)
        EndSwitch
        If $bWindowFound Then
            MsgBox(0, "Test", "Window found")
GUIDelete($TesztStopGUI)
            Return Alapjarat()
        EndIf

    WEnd
    
    
EndFunc   ;==>UD_informaciok

Func _CheckWindow()

    If WinExists($sTitle) Then
        $bWindowFound = True
        AdlibUnRegister("_CheckWindow")
    EndIf

EndFunc   ;==>_CheckWindow

I declared the globals at the start of the script

Edit: ... yeah so, forgot to tell the problem :) sry I seems to be a bit diffuse , scattered today. When I call the function, it immidietly claims that i found the window, while there is no "Információk" window on my computer (információk s the window name with the datas) 

I hope this is everything, but as usual, if you would like to know anything else, just ask!

Thank you wise coders of autoit

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

Can you please show the statement where you set $bWindowFound?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Global $bWindowFound = False

is at the beginning of the script just after the includes, with the other globals

Share this post


Link to post
Share on other sites

I would set $bWindowFound = False at the top of function UD_informaciok so when you call the function again you get the correct results.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Func UD_informaciok()

    Global $bWindowFound = False
    If Not WinExists("UD Operátor") Then
        MsgBox(0, "Üzenet", "Kérem nyissa meg az UD_OPER programot!", 10)
        Return
    EndIf
    ControlClick("UD Operátor", "", "[CLASSNN:TAdvBitBtn6]")
    WinWaitActive("Dátum beállítás", "", 5)
    ControlClick("Dátum beállítás", "", "[CLASSNN:TBitBtn1]") ;> Things i start the query with

    AdlibRegister("_CheckWindow", 1000)
    $TesztStopGUI = GUICreate('Test', 200, 100, -1, -1)
    $BTN = GUICtrlCreateButton("Exit", 10, 10, 80, 30)

    GUISetState(@SW_SHOW)
    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $BTN
                GUIDelete($TesztStopGUI)
                Return Alapjarat()
            Case GUISetOnEvent($GUI_EVENT_CLOSE, "Alapjarat") ;>I want the button to return to idle, I think i may miss something on the line, that its not correctly linked to the $BTN (use ISN Studio generally for GUI)
                GUIDelete($TesztStopGUI)
                Return Alapjarat()
        EndSwitch
        If $bWindowFound Then
            MsgBox(0, "Test", "Window found")
            GUIDelete($TesztStopGUI)
            Return Alapjarat()
        EndIf

    WEnd


EndFunc   ;==>UD_informaciok

Func _CheckWindow()

    If WinExists($sTitle) Then
        $bWindowFound = True
        AdlibUnRegister("_CheckWindow")
    EndIf

EndFunc   ;==>_CheckWindow

 same results :( 

What do you mean by when i call the function again? why would it became true from false when i declare it at the beginning as false?

Share this post


Link to post
Share on other sites

I would use the following code. Please check the comments I made in the code.

Func UD_informaciok()

    Local $bWindowFound = False  ; <== Remove Global $bWindowFound = False from the top of your script!
    If Not WinExists("UD Operátor") Then
        MsgBox(0, "Üzenet", "Kérem nyissa meg az UD_OPER programot!", 10)
        Return
    EndIf
    ControlClick("UD Operátor", "", "[CLASSNN:TAdvBitBtn6]")
    WinWaitActive("Dátum beállítás", "", 5)
    ControlClick("Dátum beállítás", "", "[CLASSNN:TBitBtn1]") ;> Things i start the query with

    AdlibRegister("_CheckWindow", 1000)
    $TesztStopGUI = GUICreate('Test', 200, 100, -1, -1)
    $BTN = GUICtrlCreateButton("Exit", 10, 10, 80, 30)

    GUISetState(@SW_SHOW)
    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $BTN
                GUIDelete($TesztStopGUI)
                AdlibUnRegister("_CheckWindow")
                Return Alapjarat()
;----------------------------------
; This block is never called because in msg mode no events are processed.
; OnEvent functions are only called when the option GUIOnEventMode is set to 1 - when in this mode GUIGetMsg() is NOT used at all.
;----------------------------------
;            Case GUISetOnEvent($GUI_EVENT_CLOSE, "Alapjarat") ;>I want the button to return to idle, I think i may miss something on the line, that its not correctly linked to the $BTN (use ISN Studio generally for GUI)
;                GUIDelete($TesztStopGUI)
;                Return Alapjarat()
        EndSwitch
        If $bWindowFound Then
            MsgBox(0, "Test", "Window found")
            GUIDelete($TesztStopGUI)
            Return Alapjarat()
        EndIf

    WEnd

EndFunc   ;==>UD_informaciok

Func _CheckWindow()

    If WinExists($sTitle) Then
        $bWindowFound = True
        AdlibUnRegister("_CheckWindow")
    EndIf

EndFunc   ;==>_CheckWindow

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Thanks, I'm actually on Opt("GUIOnEventMode", 1) could that be a problem? (sorry, I think i will start to add all my Opt and maybe even my #includes to the code I post in the forums...)

Also I started to work on the block you commented out, I tried to use this 

Case $BTN ;>I want the button to return to idle, I think i may miss something on the line, that its not correctly linked to the $BTN (use ISN Studio generally for GUI and linking them to functions or adding handles)
                GUIDelete($TesztStopGUI)
                Return Alapjarat()

On the Local idea: I'm not sure yet its woking (still running the query) but the i found the window didnT poped up yet :D

Edit: It seems to run around the way we want it waiting for the window (according to the traydebugicon), can you shed some light on why changeing it to local helped out here? I don't get it

edit2: It still running in circles :( the window poped up, and no test window found. Could this be cause by the fact that the window's title is actually: Információk 2013.07.01 - 2015.02.03 23:59:59 , the times show that from when till when do we run the query

also here is my entire code I'm trying with (maybe I just use a warning MsgBox which close after 5 sec that this can take a while)

Func UD_informaciok()

    Local $bWindowFound = False
    If Not WinExists("UD Operátor") Then
        MsgBox(0, "Üzenet", "Kérem nyissa meg az UD_OPER programot!", 10)
        Return
    EndIf
    ControlClick("UD Operátor", "", "[CLASSNN:TAdvBitBtn6]")
    WinWaitActive("Dátum beállítás", "", 5)
    ControlClick("Dátum beállítás", "", "[CLASSNN:TBitBtn1]") ;> Things i start the query with

    AdlibRegister("_CheckWindow", 1000)
    $TesztStopGUI = GUICreate('Test', 200, 100, -1, -1)
    $BTN = GUICtrlCreateButton("Exit", 10, 10, 80, 30)

    GUISetState(@SW_SHOW)
    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($TesztStopGUI)
                Return Alapjarat()
            Case $BTN ;>I want the button to return to idle, I think i may miss something on the line, that its not correctly linked to the $BTN (use ISN Studio generally for GUI and linking them to functions or adding handles)
                GUIDelete($TesztStopGUI)
                Return Alapjarat()
        EndSwitch
        If $bWindowFound Then
            MsgBox(0, "Test", "Window found")
            GUIDelete($TesztStopGUI)
            Return Alapjarat()
        EndIf

    WEnd


EndFunc   ;==>UD_informaciok

Func _CheckWindow()

    If WinExists($sTitle) Then
        $bWindowFound = True
        AdlibUnRegister("_CheckWindow")
    EndIf

EndFunc   ;==>_CheckWindow
Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

I don't know the ISN IDE but I know that event mode and message mode can't be mixed in a script.

It is import that you unregister the Adlib function not only when the window is found but as well when you leave function UD_informaciok().

So before every "Return" statement you need to add AdLinUnregister.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Sounds logical, and I understand it, thanks (and sorry first time using adlibregister)

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Hello again!

I thought I was unto something with this code:

Func Figyelmeztetes()

    Local $ans
    If Not WinExists("UD Operátor") Then
        MsgBox(0, "Üzenet", "Kérem nyissa meg az UD_OPER programot!", 10) ;if the program doesn't run then ask him to start it (there is even a function for it where you just have to select the folder
        Return
    EndIf
    $ans = MsgBox(4, "Üzenet", "Ez a lekérdezés több mint 10 percig is eltarthat!" & @CRLF & "Kívánja futtatni?") ; warning that this will take time, and are you sure you wanna run it

    If $ans = 6 Then UD_informaciok()
    If $ans = 7 Then Return

EndFunc   ;==>Figyelmeztetes

Func UD_informaciok()

    ;Local $bWindowFound = False 
    ControlClick("UD Operátor", "", "[CLASSNN:TAdvBitBtn6]")
    WinWaitActive("Dátum beállítás", "", 5)
    ControlClick("Dátum beállítás", "", "[CLASSNN:TBitBtn1]") ;> Things i start the query with

    $checkwindow = AdlibRegister("_CheckWindow", 1000)

    While True
        If $checkwindow = 1 Then
            MsgBox(0, "Test", "Window found")
            AdlibUnRegister("_CheckWindow")
            Return
        EndIf
    WEnd

EndFunc   ;==>UD_informaciok

Func _CheckWindow()

    Local $sTitle = "Információk 2013.07.01 - 2015.02.04 23.59.59" ;complete nam of the window, thinking about giving it by date variables or read it from a point in the script, but this doesnt seems to be the problem 
    If WinExists($sTitle) Then
        MsgBox(0, "Üzenet", "Lekérdezés kész", 10) ;meaning: "Message", "Query complete"
        ;AdlibUnRegister("_CheckWindow")
    EndIf

EndFunc   ;==>_CheckWindow

but somehow this instantly gives me the MsgBox(0, "Test", "Window found") if i chosse the yes option (if i chose no then it returns to idle :) at least i could handle that )

What is your opinion on my code? I think maybe in declaring the $checkwindow variable lies the problem, but not sure how else can i go about it.

Edit: also I'm tempted to try to use a simpe winwait to basicly froze my script till the query completes (I never run in to a case when it didn't completed given enoug time), but I would take that a deafet and i dont wanna accept that :)

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

$checkwindow contains 1 if AdLibRegister was able to register the function.
As this value doesn't change in the loop your code will never return the expected result.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

This is my actual last version:

Func UD_informaciok()

    ;Local $bWindowFound = False
    Local $checkwindow = 0
    ControlClick("UD Operátor", "", "[CLASSNN:TAdvBitBtn6]")
    WinWaitActive("Dátum beállítás", "",)
    ControlClick("Dátum beállítás", "", "[CLASSNN:TBitBtn1]") ;> Things i start the query with

    AdlibRegister("_CheckWindow", 1000)

    While True
        If AdlibRegister("_CheckWindow", 1000) = 1 Then $checkwindow = 1
        If $checkwindow = 1 Then
            MsgBox(0, "Test", "Window found")
            AdlibUnRegister("_CheckWindow")
            Return
        EndIf
    WEnd

EndFunc   ;==>UD_informaciok

It still doesnt do what i want it to do

Just to be clear by "AdLibRegister was able to register the function" you means it found the window, or that its run trhough the function? I mean it runs throught the function every sec, and thats exactly what is happening :)

Edit: I was digging around and after searching different functins i found the Func...Return...EndFunc shouldn't i use this instead of adlib register? I mean it could theoraticly be like that i call a function which always return 0 for example untill he doesn't find the window, then it returns 1 and that is the signal/flag for UD_informaciok to pop a window of complete! and return the entire thing in to idle

Edited by SorryButImaNewbie

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