A_ThisTimer Topic is solved

Propose new features and changes
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

A_ThisTimer  Topic is solved

06 Mar 2019, 05:47

Is this feasible?
For any given target of SetTimer (Label, function or boundfunc), then using SetTimer, % A_ThisTimer, Off inside it will turn it off.

Code: Select all

fn := Func("MyFunc").Bind(1)
SetTimer, % fn, 100
return

MyFunc(var){
	if (var)
		SetTimer, % A_ThisTimer, Off
}
Ah, I just noticed you can actually do it, the docs for SetTimer are just a little misleading.
"[v1.1.01+]: If Label is omitted, A_ThisLabel will be used. For example, SetTimer,, Off can be used inside a timer subroutine to turn off the timer"
Saying "A_ThisLabel will be used" is misleading. In the above example, A_ThisLabel cannot be used to stop the timer - SetTimer, % A_ThisLabel, Off does not work for a boundfunc. However, SetTimer, , Off does work. So A_ThisLabel is not used, something else is.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: A_ThisTimer

06 Mar 2019, 05:57

just omit A_ThisTimer? unless im misunderstanding something

Code: Select all

fn := Func("tt").Bind("asdf")
SetTimer % fn

q::g_StopTimer := true

tt(msg) {
	global g_StopTimer
	
	if (g_StopTimer)
		SetTimer, , Off

	ToolTip % msg "`n" A_TickCount
}
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: A_ThisTimer

06 Mar 2019, 06:01

evilC wrote:
06 Mar 2019, 05:47
Saying "A_ThisLabel will be used" is misleading.
There is more though,
[v1.1.24+]: If A_ThisLabel is empty but the current thread was launched by a timer, that timer is used. This is useful for timers which launch functions or function objects.
Cheers.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: A_ThisTimer

06 Mar 2019, 07:16

As a sidenote, with A_ThisTimer we could turn off a timer after we have used goto in the timer callback. It would also favour readability.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: A_ThisTimer

09 Mar 2019, 19:38

+1 for replacing empty param with A_ThisTimer in v2
SetTimer , "Off" looks weird
SetTimer(, "Off") weirder still

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 14 guests