-
-
Notifications
You must be signed in to change notification settings - Fork 385
fix(Button): add Task yield prevent block thread #7303
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone | ||
|
|
@@ -46,6 +46,7 @@ protected virtual async Task OnClickButton() | |
| { | ||
| IsAsyncLoading = true; | ||
| IsDisabled = true; | ||
| await Task.Yield(); | ||
|
||
| } | ||
|
|
||
| await HandlerClick(); | ||
|
|
||
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.
After setting
IsAsyncLoadingandIsDisabledto true,StateHasChanged()should be called to immediately update the UI before yielding control. This ensures the loading indicator and disabled state are rendered before the async operation continues. ThePopConfirmButtoncomponent follows this pattern by callingStateHasChanged()immediately after setting these properties (see PopConfirmButton.razor.cs lines 100-101).