Settimer limit Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
renArD
Posts: 36
Joined: 17 Feb 2020, 18:23

Settimer limit

17 Feb 2020, 18:57

Dear experts,

I dare to ask a question about Settimer. Bellow is a short example. I don't understand why the msgbox "after settimer" doesn't show if the timer delay is too short (10) but works if long enough (100).

Code: Select all

settimer, mylabel, -10
msgbox after settimer
return

mylabel:
msgbox in mylabel timer
Could anyone explain me ?

Thanks
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Settimer limit

17 Feb 2020, 19:08

You need to add a return to the end of your timed routine or it never ends.
renArD
Posts: 36
Joined: 17 Feb 2020, 18:23

Re: Settimer limit

17 Feb 2020, 19:39

Thank you very much, Hellbent, for your helpful answer.
Please let me refine my question :

Code: Select all

msgbox first
settimer, mylabel, -10
msgbox ,,name to detect,can it load ?
return

mylabel:
WinWait name to detect
msgbox in mylabel timer
return
Why does "can it load" only appears if timer is set to 100 (but not to 10, like above) ?
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Settimer limit

17 Feb 2020, 19:58

Because you have it waiting for the second message to appear. So that's what it does, it waits, and waits, and waits...
renArD
Posts: 36
Joined: 17 Feb 2020, 18:23

Re: Settimer limit

18 Feb 2020, 00:58

Thanks for your answer !

May I ask why it works with 100ms ?

I understood that settimer makes a new parallel thread which works besides the main stream which loaded it.
Here, with 10ms, it's like if nothing is executed after settimer if the timer (the labeled portion) hasn't finish (that would explain it waits for ever, as in your answer). However, with 100ms it works like expected.
Is there a limit value between two behaviours ?

I hope I'm clear !
renArD
Posts: 36
Joined: 17 Feb 2020, 18:23

Re: Settimer limit

24 Feb 2020, 13:02

Hi, I don't want to disturb but I sincerely didn't understand. Can someone tell me ?
renArD
Posts: 36
Joined: 17 Feb 2020, 18:23

Re: Settimer limit

11 Mar 2020, 03:59

Hi, doesn't anyone consider the above mentioned AHK's behaviour as strange ? Please help to know at least if I'm dumb :crazy:
Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Settimer limit

11 Mar 2020, 05:32

Hallo,
a timer thread does not run parallel!
As soon as the timer starts the main thread is paused and only the timer is executed.
The main thread only continues when the timer thread ends.

Code: Select all

msgbox first
settimer, mylabel, -1000
Sleep, 980 ;here: 980 works but 990 not!
msgbox ,,name to detect,can it load ?
return

mylabel:
WinWait name to detect
msgbox in mylabel timer
return
renArD
Posts: 36
Joined: 17 Feb 2020, 18:23

Re: Settimer limit

11 Mar 2020, 06:03

Dear Rohwedder, you made me understand, thank you very much !

I don't know if my code was clear enough to understand what I intended to do : I'd like to change position and/or buttons of a window as soon as possible after loading it. So I wanted to run a "settimer" routine just before creating the window so that the routine is ready to modify the window. If the timer is loaded a long time enough (100ms) after the settimer command, the window has the time to load but this way of doing doesn't fit the "as soon as possible" requirement. If the timer is loaded too quickly (10ms), the window doesn't have the time to appear and the winwait blocks. I could also run the timer periodically (with no blocking stuff in it) but I'd like it's routine to execute once.

For your information, here is the window :

Code: Select all

MsgBox, 35, %title% - Confirmation,blabla
And here is what I execute in routine :

Code: Select all

watchBoxConfirmWindow:
{
	winwait, %title% - Confirmation

	controlSetText, Button1, This, %title% - Confirmation
	controlSetText, Button2, That, %title% - Confirmation
	controlSetText, Button3, Zout, %title% - Confirmation

	return
}
I can't put the controlSetText lines after loading the window (without any settimer stuff), because the lines won't be executed until the window is closed.

If you have any idea for doing that, It would be appreciated :)
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Settimer limit

11 Mar 2020, 06:21

Following should be the shortest reliable time to show next line first. See remarks in Sleep

Code: Select all

SetBatchLines, -1
settimer, mylabel, -17
msgbox after settimer
return

mylabel:
msgbox in mylabel timer
return
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Settimer limit

11 Mar 2020, 06:52

@HotKeyIt

Wouldn't the amount of time that it takes for the msgbox to be constructed play any part in it?
renArD
Posts: 36
Joined: 17 Feb 2020, 18:23

Re: Settimer limit

11 Mar 2020, 07:01

Thank you very much, HotKeyIt, for this answer. However, I did not completely understood it.
Why did you set settimer to "-17" ? The documentation of Sleep mentions 10ms or 15.6 (which would be rounded to 16ms, not 17ms). However, I notice that setting -16 blocks however -17 not (without the "SetBatchLines, -1" command, but it's probably because my computer does nothing else at the moment).
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Settimer limit

11 Mar 2020, 07:28

Per my previous post, after a quick test I can confirm that the time it takes to construct the msgbox is a dominate factor in this scenario.


This works fine, shows two msgboxes at once.

Code: Select all

SetBatchLines, -1
settimer, mylabel, -17
msgbox after settimer
return

mylabel:
msgbox in mylabel timer
return
This only shows one msgbox at a time, the first being the one in the timer and if there was a winwait command in the timer it would just sit there waiting forever.

Code: Select all

SetBatchLines, -1
text:= "I don't know if my code was clear enough to understand what I intended to do : I'd like to change position and/or buttons of a window as soon as possible after loading it. So I wanted to run a  routine just before creating the window so that the routine is ready to modify the window. If the timer is loaded a long time enough (100ms) after the settimer command, the window has the time to load but this way of doing doesn't fit the  requirement. If the timer is loaded too quickly (10ms), the window doesn't have the time to appear and the winwait blocks. I could also run the timer periodically (with no blocking stuff in it) but I'd like it's routine to execute once."
settimer, mylabel, -17
msgbox, % text
return

mylabel:
msgbox in mylabel timer
return

***Note***
If you have a faster computer than mine, you may have to add some more text or add more options to the msgbox to get the same result, but the point is that unfortunately, minimum time is variable.
renArD
Posts: 36
Joined: 17 Feb 2020, 18:23

Re: Settimer limit

11 Mar 2020, 07:37

This is very interesting, thank you for this tests and conclusions.
Even if my computer is faster, it may vary in speed from one time to another and the program has to work on other computers. So it encourages to put "enough" wait time (like -100ms) to be "sure". Unfortunately it's impossible to really be sure so one might have the program blocked (or, if I remove the winwait, one might have bad button names), and all others will wait a "long" time to see the buttons changing.

Maybe you have any idea to change the buttons of the msgbox ?
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Settimer limit

11 Mar 2020, 07:40

renArD wrote:
11 Mar 2020, 07:37
Maybe you have any idea to change the buttons of the msgbox ?
Just make your own gui. Then you don't need the timer at all.
Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Settimer limit  Topic is solved

11 Mar 2020, 07:52

Or:

Code: Select all

title = Blabla
MsgBoxTitle = %title% - Confirmation
FileDelete, ~.ahk
FileAppend,
(
winwait, %MsgBoxTitle%,,1
controlSetText, Button1, This, %MsgBoxTitle%
controlSetText, Button2, That, %MsgBoxTitle%
controlSetText, Button3, Zout, %MsgBoxTitle%
), ~.ahk
Run, ~.ahk
MsgBox, 35,% MsgBoxTitle,blabla
renArD
Posts: 36
Joined: 17 Feb 2020, 18:23

Re: Settimer limit

11 Mar 2020, 07:55

Hellbent wrote:
11 Mar 2020, 07:40
renArD wrote:
11 Mar 2020, 07:37
Maybe you have any idea to change the buttons of the msgbox ?
Just make your own gui. Then you don't need the timer at all.
I feared you answer this solution !
The msgbox command is very handy : it adapts to text size, it is easy to get button checked (IfMsgBox), it has built in images, etc. As far as I know about Gui, it isn't as easy to use/configure/adapt.
renArD
Posts: 36
Joined: 17 Feb 2020, 18:23

Re: Settimer limit

11 Mar 2020, 08:15

Rohwedder wrote: Or:

Code: Select all

title = Blabla
MsgBoxTitle = %title% - Confirmation
FileDelete, ~.ahk
FileAppend,
(
winwait, %MsgBoxTitle%,,1
controlSetText, Button1, This, %MsgBoxTitle%
controlSetText, Button2, That, %MsgBoxTitle%
controlSetText, Button3, Zout, %MsgBoxTitle%
), ~.ahk
Run, ~.ahk
MsgBox, 35,% MsgBoxTitle,blabla
This is an intersting solution, thank you. I guess this is the only way to create multiple threads ?
Is there anyway to automatically delete the created file ?
Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Settimer limit

11 Mar 2020, 08:49

Of course!

Code: Select all

title = Blabla
MsgBoxTitle = %title% - Confirmation
FileAppend,
(
winwait, %MsgBoxTitle%,,1
controlSetText, Button1, This, %MsgBoxTitle%
controlSetText, Button2, That, %MsgBoxTitle%
controlSetText, Button3, Zout, %MsgBoxTitle%
FileDelete, ~.ahk
), ~.ahk
Run, ~.ahk
MsgBox, 35,% MsgBoxTitle,blabla
renArD
Posts: 36
Joined: 17 Feb 2020, 18:23

Re: Settimer limit

11 Mar 2020, 08:51

renArD wrote:
11 Mar 2020, 08:15
Is there anyway to automatically delete the created file ?
I just added "FileDelete, ~.ahk" at the end of the append lines

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb and 339 guests