I have a Windows application that is supposed to do something every 40 milliseconds precisely (actually it can be configured to anything, but 40 msec is a typical setting). It has plenty of time to do its tasks, so most of that time slice is spent idle, but it needs to report at precise intervals. We continually monitor to see whether it is taking more or less than 40 milliseconds to report in reality.
Under Windows 7, 8 or 10, it performed well. Under Windows 11, we have a new problem: the application performs well only as long as its windows are not hidden. If its windows are hidden behind the maximized window of another application (Firefox, notepad, anything), then after 5 seconds the timing becomes jagged - overshoots the 40 msec deadline, then undershoots to compensate, then overshoots again, and so on. If you alt-tab back to our application's window, you have to wait another 5 seconds but then the timing goes back to being smooth.
This happens only if the application is behind a maximized window: if the application's windows are hidden behind a non-maximized notepad window and there's just a little bit of bare desktop showing somewhere, then the timing stays smooth the whole time.
Seemingly, Windows 11's window manager is taking the decision, based on the maximization of notepad or whatever, to put our app into some kind of "background" mode. What is this mode? Is there some Windows API call my application can make, to prevent itself getting put into this mode?
We have found one way of making it worse: if we register the process using SetCurrentProcessExplicitAppUserModelID(), then we get different behavior: specifically, we get exactly 10 seconds' worth of good performance, then it goes bad and stays bad no matter whether we're in the foreground or background. That might be a clue but I'm not sure which direction it points, to fix the original problem.
In case it is relevant: our application is written in C++, compiled with MSVC, and uses Qt 6 for its windows.
The phenomenon appears to be called "process power throttling". The following paragraphs from Microsoft's
SetProcessInformation()documentation seem relevant:We were actually able to fix the timing problem described in the question, by addressing just the second point: