[SOLVED] WinWait high CPU usage Topic is solved

Get help for the alpha version of AutoHotkey v2 here. Please state the v2 version you are working with in the title when making a new topic.
gyohza
Posts: 2
Joined: 23 Sep 2019, 09:09
GitHub: gyohza

[SOLVED] WinWait high CPU usage

23 Sep 2019, 09:47

[Moderator's note: Topic moved from AutoHotkey v2 Development.]

I'm having an issue similar to the one pointed out here.

I stuck to the WinExist workaround suggested by jethrow back in 2011, with a 200ms delay, which reduces the CPU consumption from 15% to an average 2.5% (running AHK 2a over an i5-4590 quad-core CPU). By what Lexikos said back in the day, it should have been fixed by AHK 1.1.

The workaround is working fine and all, but still the 200ms delay bugs me a bit - I'm using it to skip ads on certain app but they still get to pop up for a few milliseconds in between the sleeping gaps. If I reduce the delay to 100ms, CPU reasonably doubles. I was wondering if it's the very same issue as before and if it can be fixed just as it did back then.

Sorry I'm posting this on the wrong board or if it sounds a bit irrelevant. I've been using AHK for many years, now (almost 5 years), became a programmer because of it and still it's the first time I've ever posted here. :P
Last edited by gyohza on 09 Oct 2019, 08:11, edited 1 time in total.
swagfag
Posts: 2918
Joined: 11 Jan 2017, 17:59

Re: WinWait high CPU usage

23 Sep 2019, 13:04

post concrete examples
ur snippet ported to v2 results in 0.57% cpu utilization for me on a105

Code: Select all

SetTimer "Timer", -3000
msgbox "Keep this window open for 3 secs & the WinWait causes 100% CPU`n`nClose it before 3 secs & the WinWait will use 0% CPU"

Timer() {
	Tooltip "WinWait running..."
	WinWait "PLEASE USE 100% CPU FOR NO REASON"
	msgbox "WinWait done"
}
gyohza
Posts: 2
Joined: 23 Sep 2019, 09:09
GitHub: gyohza

Re: WinWait high CPU usage  Topic is solved

09 Oct 2019, 08:11

Yeah, I guess you're right. Yours wasn't really using up a lot of CPU, so I started to think it was because of Regex title matching, but when I tried tinkering around I found out the real culprit:

Code: Select all

DetectHiddenWindows "On"
This was causing every Window procedure to use more CPU than it should.

Here's my past snippet for reference:

Code: Select all

adless() {
	loop {
		if (WinExist("^(title1|title2|title3)$ ahk_class ^Chrome_WidgetWin_0$ ahk_exe ^.*\\someapp\\theapp\.exe$")) {
			/*
				do stuff
			*/
		} else {
			Sleep 100
		}
	}
}

SetTimer("adless", -1)
And here's the version with actual WinWait:

Code: Select all

adless() {
	loop {
		WinWait("^(title1|title2|title3)$ ahk_class ^Chrome_WidgetWin_0$ ahk_exe ^.*\\someapp\\theapp\.exe$")
		/*
			do stuff
		*/
	}
}

SetTimer("adless", -1)
Consider it solved! Thanks for the heads up.

Return to “AutoHotkey v2 Help”

Who is online

Users browsing this forum: No registered users and 2 guests