-
Notifications
You must be signed in to change notification settings - Fork 2k
[Windows] Fix PlatformTicker.Windows.cs — IsRunning always returns false #35840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kubaflo
merged 4 commits into
dotnet:inflight/current
from
HarishwaranVijayakumar:fix-animation/plarformticker
Jun 19, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/Core/tests/DeviceTests/Animations/PlatformTickerTests.Windows.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Maui.Animations; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Maui.DeviceTests | ||
| { | ||
| [Category(TestCategory.Animation)] | ||
| public class PlatformTickerTests : TestBase | ||
| { | ||
| [Fact] | ||
| public async Task IsRunning_ReflectsStartAndStop() | ||
| { | ||
| await InvokeOnMainThreadAsync(() => | ||
| { | ||
| var ticker = new PlatformTicker(); | ||
|
|
||
| Assert.False(ticker.IsRunning, "Should be false before Start"); | ||
|
|
||
| ticker.Start(); | ||
| Assert.True(ticker.IsRunning, "Should be true after Start"); | ||
|
|
||
| ticker.Stop(); | ||
| Assert.False(ticker.IsRunning, "Should be false after Stop"); | ||
| }); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Start_IsIdempotent_NoDuplicateSubscriptions() | ||
| { | ||
| await InvokeOnMainThreadAsync(async () => | ||
| { | ||
| var ticker = new PlatformTicker(); | ||
| int fireCount = 0; | ||
| ticker.Fire = () => fireCount++; | ||
|
|
||
| ticker.Start(); | ||
| ticker.Start(); // second call should be a no-op | ||
| ticker.Start(); // third call should be a no-op | ||
|
|
||
| // Yield a few composition frames | ||
| await Task.Delay(100); | ||
|
|
||
| ticker.Stop(); | ||
| var firesAfterStop = fireCount; | ||
|
|
||
| await Task.Delay(50); | ||
|
|
||
| // No additional fires after Stop | ||
| Assert.Equal(firesAfterStop, fireCount); | ||
| // ~6 expected at 60Hz over 100ms; 3x subscriptions would yield ~18+ | ||
| Assert.InRange(firesAfterStop, 1, 20); | ||
| }); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task AnimationManager_StartsTickerOnce_AcrossMultipleAdds() | ||
| { | ||
| await InvokeOnMainThreadAsync(() => | ||
| { | ||
| var ticker = new PlatformTicker(); | ||
| var manager = new AnimationManager(ticker); | ||
|
|
||
| for (int i = 0; i < 5; i++) | ||
| manager.Add(new Animation { Duration = 1.0 }); | ||
|
|
||
| Assert.True(ticker.IsRunning); | ||
|
|
||
| ticker.Stop(); | ||
| Assert.False(ticker.IsRunning); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[major] Regression Prevention and Test Coverage — This assertion does not actually catch the duplicate-subscription regression. With the pre-fix implementation, three
Start()calls can produce roughly 18 callbacks over 100ms, which still passes the current upper bound of 20. That means the test can pass whileStart()is not idempotent. Tighten this to prove duplicate subscriptions are not occurring, for example by comparing against a single-start baseline or using a deterministic frame signal rather than a broad timing range.