c# - 在这个函数中放在哪里等待?

标签 c# asynchronous

 protected override async void OnNavigatedTo(NavigationEventArgs e)
 {
       base.OnNavigatedTo(e);

       var content = (Content) Application.Current.Resources["NavigationParam"];

       titleName.Text = content.title;
       var uri = new Uri(content.url, UriKind.Absolute);
       imageShow.Source = new BitmapImage(uri);
 }

Severity Code Description Project File Line Column Warning CS1998 This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. ImageParser C:\Users\Johny\Documents\Visual Studio 2015\Projects\ImageParser\ImdbSample\ItemView.xaml.cs 26 41

最佳答案

您没有在方法主体内等待任何异步操作(通过使用 await 运算符),因此您的方法定义中的 async 关键字不是必需的。只需删除它,警告就会消失。

这不会改变您的方法的语义。正如警告消息明确指出的那样,它已经同步运行了。

关于c# - 在这个函数中放在哪里等待?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34038080/

相关文章:

c - 在 C 中编写异步事件服务器的推荐模式

asynchronous - 无法加入 ev 循环线程,因为它卡在 epoll_wait() 中

c# - 室内Wi-Fi定位API?

c# - 更改位图图像的不透明度

javascript - 如何从异步调用返回响应?

model-view-controller - Spring MVC 和 @Async

javascript - 尝试点击加载外部插件不起作用

c# - 从 VB 转换为 C#

c# - UWP BLE 广告状态已中止

c# - 如何解决以下错误 : cannot convert from 'int' to 'System. Collections.Generic.IEnumerable<int>?