Sign in to follow this  
Followers 0
Champak

_Timer_SetTimer problem

5 posts in this topic

Just want to make sure I understand this function because it is failing sometimes. I have a _Timer_SetTimer set up to call a function after the countdown. Is it suppose to be a GUARANTEE that the timered function being called is going to activate regardless if another function is taking place at that exact moment? Basically if another function is activating at that time, should the timered function be queued to activate after the current function, or should it interrupt the current function? Or will it just "die" if it is unable to run if a function is currently active? I would think it should be queued or something, but that is not happening.

Any suggestions on how to solve this?

Share this post


Link to post
Share on other sites



Just want to make sure I understand this function because it is failing sometimes. I have a _Timer_SetTimer set up to call a function after the countdown. Is it suppose to be a GUARANTEE that the timered function being called is going to activate regardless if another function is taking place at that exact moment? Basically if another function is activating at that time, should the timered function be queued to activate after the current function, or should it interrupt the current function? Or will it just "die" if it is unable to run if a function is currently active? I would think it should be queued or something, but that is not happening.

Any suggestions on how to solve this?

When the timer times out it will call its function regardless of what is happening afaik. For example, it can be usd to call a function when a dialog is showing which would normally block other operations.

If your problem is that it does operate and you don't want it to then you can have the timer function set a variable and then when its appropriate call the real function if the variable is set.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Basically I have a timered function that just isn't firing sometimes. I suspected it was because another function might happen to be activating at that very instance thus causing the timered function not to fire. But if that isn't the case, I guess I'll look deeper.

Share this post


Link to post
Share on other sites

When the timer times out it will call its function regardless of what is happening afaik. For example, it can be usd to call a function when a dialog is showing which would normally block other operations.

If your problem is that it does operate and you don't want it to then you can have the timer function set a variable and then when its appropriate call the real function if the variable is set.

Wow. That's kind of fun to play around with! Your script can in fact modify it's own MsgBox() if you call the function to do it with a timer. Demo:
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <Timers.au3>

Opt("MustDeclareVars", 1)

Global $hGUI, $ctrlEdit1, $ctrlButton1, $CtrlButton2, $iTimer, $iClock = 0

$hGUI = GUICreate("Test", 400, 300)
$ctrlEdit1 = GUICtrlCreateEdit("", 10, 10, 380, 240, BitOR($WS_HSCROLL, $WS_VSCROLL))
$ctrlButton1 = GUICtrlCreateButton("START", 75, 260, 100, 30)
$CtrlButton2 = GUICtrlCreateButton("MsgBox", 225, 260, 100, 30)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _Timer_KillAllTimers($hGUI)
            Exit
        Case $ctrlButton1
            $iClock = 0
            _Timer_KillTimer($hGUI, $iTimer)
            $iTimer = _Timer_SetTimer($hGUI, 1000, "_UpdateClock"); create 1sec timer
        Case $CtrlButton2
            MsgBox(64, "Test", "Test message.")
    EndSwitch
WEnd

; call back function
Func _UpdateClock($hWnd, $Msg, $iIDTimer, $dwTime)
    Local $avWin
    #forceref $hWnd, $Msg, $iIDTimer, $dwTime
    $iClock += 1
    ControlSetText($hGUI, "", $ctrlEdit1, $iClock & "sec")
    If WinExists("[CLASS:#32770; TITLE:Test]") Then
        $avWin = WinGetPos("[CLASS:#32770; TITLE:Test]")
        WinMove("[CLASS:#32770; TITLE:Test]", "", $avWin[0] + 3, $avWin[1] + 3, $avWin[2] + 3, $avWin[3] + 3)
    EndIf
EndFunc  ;==>_UpdateClock

I hadn't considered that possibility before.

:)


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

Wow. That's kind of fun to play around with! Your script can in fact modify it's own MsgBox() if you call the function to do it with a timer. Demo:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <Timers.au3>

Opt("MustDeclareVars", 1)

Global $hGUI, $ctrlEdit1, $ctrlButton1, $CtrlButton2, $iTimer, $iClock = 0

$hGUI = GUICreate("Test", 400, 300)
$ctrlEdit1 = GUICtrlCreateEdit("", 10, 10, 380, 240, BitOR($WS_HSCROLL, $WS_VSCROLL))
$ctrlButton1 = GUICtrlCreateButton("START", 75, 260, 100, 30)
$CtrlButton2 = GUICtrlCreateButton("MsgBox", 225, 260, 100, 30)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _Timer_KillAllTimers($hGUI)
            Exit
        Case $ctrlButton1
            $iClock = 0
            _Timer_KillTimer($hGUI, $iTimer)
            $iTimer = _Timer_SetTimer($hGUI, 1000, "_UpdateClock"); create 1sec timer
        Case $CtrlButton2
            MsgBox(64, "Test", "Test message.")
    EndSwitch
WEnd

; call back function
Func _UpdateClock($hWnd, $Msg, $iIDTimer, $dwTime)
    Local $avWin
    #forceref $hWnd, $Msg, $iIDTimer, $dwTime
    $iClock += 1
    ControlSetText($hGUI, "", $ctrlEdit1, $iClock & "sec")
    If WinExists("[CLASS:#32770; TITLE:Test]") Then
        $avWin = WinGetPos("[CLASS:#32770; TITLE:Test]")
        WinMove("[CLASS:#32770; TITLE:Test]", "", $avWin[0] + 3, $avWin[1] + 3, $avWin[2] + 3, $avWin[3] + 3)
    EndIf
EndFunc ;==>_UpdateClock

I hadn't considered that possibility before.

:)

Yes, that's a nice example PsaltyDS. I find it useful to put the msgbox or dialog inside the window it's called from because to me it seems confusing if a message box pops up nowhere near the window it's related to; how do you know which program it belongs to? This is a bit off topic but I've used a timer to move and read the annoying FileSaveDialog. FileSaveDialog seems to insist on opening top left when I don't want it to. Also, when someone chooses an extension type and enters the file name without the extension then FileSaveAs returns only the filename and you can't tell what extension was chosen. But using the timer to call a function which reads the window text you can see which extension has been selected.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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