-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Add async event handler support #16237
Comments
@rynowak Looking for your opinion on how this would fit best with dotnet/blazor#516. |
My guess is that we could handle this with overloading in the runtime, which means that we wouldn't require different event names. We could do different event names of course, if we wanted to. We could test this theory by adding and additional overload to |
I suspect also that we'll want to require C# 7.3 for this. dotnet/csharplang#98 The difference is that in C# 7.2:
This is considered an ambiguity in C#7.2 but not in C# 7.3. Any concerns with this plan? |
Hello ! Any news on this subject ?
In order to have an async delegate called from my synchronous event, as my dispatched task with my SetTimeout helper is only waiting an Action type as delegate. Otherwise do i missing something on the attribute binding for an async event ? |
We're planning to do this for 0.3.0. If you want a slightly less gross workaround, you can use
The only thing that's missing is that you have to call |
Perfect ! Thanks a lot @rynowak ! |
This feature has been merged for 0.3.0 to the dev branch e5fd24b Important - as of 0.3.0 we will require the use of C# 7.3. Using async event handlers smoothly will require some changes that have been made to overload resolution in C# 7.3. You can find their instructions for setting the C# language version in their documentation here. Note that you may need to restart visual studio if you change the language version for a project. Async event handlers work a lot like regular event handlers except... well they are async. Updating @Daddoon 's example: ...
<li>
<a onclick="@LogoutUser">@ResourceHelper.Get(nameof(Resources.LogOut))</a>
</li>
...
@functions {
private async Task LogoutUser(UIMouseEventArgs e)
{
await Task.Delay(10);
// The runtime will call StateHasChanged the first time you 'await'
bool success = await SignInManager.LogoutAsync();
if (success == false)
{
JConsole.AlertDangerAnErrorOccured();
}
// The runtime will call StateHasChanged again when your task completes
}
} |
Now we support
oneventname="@MyMethod"
, we should create some built-in way to deal withMyMethod
returningTask
and having the renderer auto-rerender after that task completes.Not sure whether this requires a syntax like
oneventname-async
or whether we can do it withoneventname
dynamically based on the assigned value type.The text was updated successfully, but these errors were encountered: