首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Blazor (异步任务OnInitializedAsync)生命周期中使用两个等待不能正常工作

在Blazor (异步任务OnInitializedAsync)生命周期中使用两个等待不能正常工作
EN

Stack Overflow用户
提问于 2020-01-03 17:42:30
回答 1查看 834关注 0票数 0

我在一个操作中使用了以下方法。

代码语言:javascript
复制
protected override async Task OnInitializedAsync()
{
    forecasts = await Http.GetJsonAsync<WeatherForecast[]>("sample-data/weather.json");
    await someOperation(); // this action is not perfomred
}

关于此查询的任何建议

EN

回答 1

Stack Overflow用户

发布于 2020-07-08 06:55:07

我以前遇到过这个问题,我能够像这样解决它:

代码语言:javascript
复制
protected override async Task OnInitializedAsync()
{
    Http.GetJsonAsync<WeatherForecast[]>("sample-data/weather.json").ContinueWith(task => forecasts = task.Result); //Creates a continuation that executes asynchronously when the target Task completes.


    await someOperation(); // his action can also be done using ContinueWith if needed
}

ContinueWith文档:

希望这能有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59576210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档