Why are you using "async void" in BlazoredModal.razor? #422
Replies: 1 comment 1 reply
-
Hey Nekrasov, To be honest, I can't remember how things got into this state. I'm guessing the event handlers, originally didn't need to be async and at some point it got changed. But you're correct it, shouldn't be async void. The reason for async void is becuase of how the events are defined on the The real fix here is to change the events to be The good news is with the next release we're breaking a few things so this is going to be the best time to do it I think. I'm going to convert this to an issue so it can be worked on. |
Beta Was this translation helpful? Give feedback.
-
Good day Chris,
My name is Andrii,
I use your good library "BlazoredModal" in my projects.
This is a very handy library for working with popups.
When I was review the source code, I noticed that you are using "async void" in BlazoredModal.razor file.
Why are you using "async void" in BlazoredModal.razor?
Microsoft's guidelines say that using "async void" is bad practice.
Could you please replace "async void" with "async Task" because it's a potential threat on exceptions?
I assumed you wanted to use "await" to change the state of the component.
In methods using "async Task" you can also cause an immediate redraw of the state of the component.
I'm using the following approach, which always works.
For example:
private async Task StateHasChangedAsync() { StateHasChanged(); await Task.Delay(1); }
Beta Was this translation helpful? Give feedback.
All reactions