-
-
Notifications
You must be signed in to change notification settings - Fork 363
feat(Timer): remove Task.Run support wpf #5896
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
Conversation
Reviewer's Guide by SourceryThis pull request refactors the No diagrams generated as the changes look simple and do not need a visual representation. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Pull Request Overview
This PR refactors the Timer component’s OnStart method to simplify asynchronous handling and improve readability by removing the Task.Run call.
- Changed OnStart from synchronous wrapping to an async method with proper state updates.
- Removed the Task.Run block and replaced some InvokeAsync calls with direct StateHasChanged calls.
Comments suppressed due to low confidence (1)
src/BootstrapBlazor/Components/Timer/Timer.razor.cs:180
- Removing the Task.Run block means the timer loop now runs on the UI thread, which might lead to UI blocking if the countdown operation is extensive. Consider using a background timer or a dedicated task to offload this processing.
_ = Task.Run(async () => {
| CurrentTimespan = Value; | ||
| AlertTime = DateTime.Now.Add(CurrentTimespan).ToString("HH:mm:ss"); | ||
|
|
||
| StateHasChanged(); |
Copilot
AI
Apr 26, 2025
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.
[nitpick] If using await Task.Yield() to force an async context switch, please consider adding a brief comment explaining its purpose to aid future maintainers.
| StateHasChanged(); | |
| StateHasChanged(); | |
| // Force an asynchronous context switch to ensure UI updates are processed before continuing. |
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.
Hey @ArgoZhang - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider updating the PR title to more accurately reflect the changes, as the modified code relates to a Blazor component rather than WPF.
- Could you add a brief explanation for the addition of
await Task.Yield()at the start of theOnStartmethod?
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
|
||
| private Task OnStart(TimeSpan val) | ||
| private async Task OnStart(TimeSpan val) | ||
| { |
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.
suggestion (performance): Synchronous ResetEvent.WaitOne call inside an async method.
Using ResetEvent.WaitOne is a blocking operation and may block the async state machine if executed on a UI or a limited thread pool thread. Consider leveraging an asynchronous wait mechanism to avoid potential deadlocks or UI freezes.
Suggested implementation:
if (IsPause)
{
await Task.Run(() => ResetEvent.WaitOne());
AlertTime = DateTime.Now.Add(CurrentTimespan).ToString("HH:mm:ss");
}Make sure the surrounding method is declared as async and that any callers are updated accordingly. This change leverages an asynchronous wait for the ResetEvent to avoid blocking the async flow.
This reverts commit eadd595.
This reverts commit d93de98.
* Revert "feat(Timer): remove Task.Run support wpf (#5896)" This reverts commit eadd595. * Reapply "feat(Timer): remove Task.Run support wpf (#5896)" This reverts commit d93de98. * refactor: 优化性能 * chore: bump version 9.5.11-beta06 Co-Authored-By: wengy <[email protected]> * test: 更新单元测试 * test: 增加单元测试 --------- Co-authored-by: wengy <[email protected]>
Link issues
fixes #5895
Summary By Copilot
This pull request refactors the
OnStartmethod in theTimer.razor.csfile to simplify the code and improve its readability. The most notable changes include making the method asynchronous, removing unnecessaryTask.Runcalls, and simplifying state updates.Refactoring of
OnStartmethod:OnStartmethod fromprivate Tasktoprivate async Taskto directly handle asynchronous operations without wrapping them inTask.Run.Task.Runblock and consolidated the logic to simplify the flow, ensuring state updates (StateHasChanged) and event invocations (OnTimeout) are directly handled.await InvokeAsync(StateHasChanged)with a direct call toStateHasChangedto streamline the state update process.Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Simplify asynchronous operations in the Timer component by refactoring the
OnStartmethod.Enhancements:
OnStartmethod asynchronous, removing the need forTask.Run.OnStartmethod.