Skip to content

Conversation

@lhecker
Copy link
Member

@lhecker lhecker commented Aug 4, 2025

You can now create throttled functions which trigger both on the leading
and trailing edge. This was then also ported to ThrottledFunc for
DispatcherQueues and used for title/taskbar updates.

Closes #19188

Validation Steps Performed

  • In CMD run:
    FOR /L %N IN () DO @echo %time%
  • Doesn't hang the UI ✅

toolTipInterval,
til::throttled_func_options{
.delay = std::chrono::milliseconds{ hoverTimeoutMillis },
.debounce = true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try jiggling your cursor over the minimize/maximize buttons and the popup will flicker. By setting debounce=true here this is also fixed.

co_await winrt::resume_background();

CompletionsChanged.raise(*this, *args);
CompletionsChanged.raise(*this, winrt::make<CompletionsChangedEventArgs>(winrt::hstring{ menuJson }, replaceLength));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, this is a drive by change. I did it initially when I considered going a different route with this and I can back it out.

The reason I kept this is because this is the only function which yields to a background thread before invoking the callback. We shouldn't do that to keep it consistent (no surprises).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine with me


if (execute)
{
_execute(std::move(args), schedule);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this move from args twice, once on R106 and once on R115, if the function is both leading and trailing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because the condition for executing here is !timerRunning && _leading which is the same condition as above that precludes it from being moved.

const auto toolTipInterval = std::chrono::milliseconds(hoverTimeoutMillis);
if (FAILED(SystemParametersInfoW(SPI_GETMOUSEHOVERTIME, 0, &hoverTimeoutMillis, 0)))
{
hoverTimeoutMillis = 400;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does SystemParametersInfoW destroy the value on failure? bah!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know that, but I don't believe that we should rely on the assumption that it doesn't. I doubt that this was tested in some way too (after all, can this call even fail?).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reviewing the kernel code, I found that the call can never fail.

co_await winrt::resume_background();

CompletionsChanged.raise(*this, *args);
CompletionsChanged.raise(*this, winrt::make<CompletionsChangedEventArgs>(winrt::hstring{ menuJson }, replaceLength));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine with me

@DHowett DHowett moved this to To Consider in 1.23 Servicing Pipeline Aug 4, 2025
@lhecker lhecker merged commit dbf740c into main Aug 4, 2025
19 checks passed
@lhecker lhecker deleted the dev/lhecker/19188-throttle branch August 4, 2025 18:25
@DHowett DHowett moved this from To Consider to To Cherry Pick in 1.23 Servicing Pipeline Sep 16, 2025
@DHowett DHowett moved this from To Cherry Pick to Cherry Picked in 1.23 Servicing Pipeline Sep 16, 2025
DHowett pushed a commit that referenced this pull request Sep 16, 2025
You can now create throttled functions which trigger both on the leading
and trailing edge. This was then also ported to `ThrottledFunc` for
`DispatcherQueue`s and used for title/taskbar updates.

Closes #19188

* In CMD run:
  ```batch
  FOR /L %N IN () DO @echo %time%
  ```
* Doesn't hang the UI ✅

SERVICE NOTES
This replays part of #19192 to make it compatible with throttled_func.

(cherry picked from commit dbf740c)
Service-Card-Id: PVTI_lADOAF3p4s4AxadtzgdI2TQ PVTI_lADOAF3p4s4AxadtzgdSMv0
Service-Version: 1.23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Cherry Picked

Development

Successfully merging this pull request may close these issues.

Infinite loop in Command Prompt makes the whole Terminal window unresponsive

3 participants