Nil*_*zor 30 c# async-await windows-runtime windows-store-apps
我在Metro应用程序的一部分中发生异常时触发了以下方法
void Model_ExceptionOccured(Exception ex)
{
var dlg = new Windows.UI.Popups.MessageDialog("An exception occured during verification: " + ex.Message, "Exception");
dlg.ShowAsync();
}
Run Code Online (Sandbox Code Playgroud)
'dlg.ShowAsync()' - 调用是异步的,但我不在乎等待结果.编译器会为它生成警告:
Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
我应该关心吗?有什么理由我应该添加await关键字,除了摆脱警告?
小智 28
根据以下链接,alexm给出的答案是不正确的.在等待的异步调用期间抛出的异常将丢失.要消除此警告,您应该将异步调用的Task返回值分配给变量.这可确保您可以访问抛出的任何异常,这些异常将在返回值中指示.
http://msdn.microsoft.com/en-us/library/hh965065(v=vs.110).aspx(VB.NET)
http://msdn.microsoft.com/en-us/library/hh873131.aspx(C#)
| 归档时间: |
|
| 查看次数: |
11704 次 |
| 最近记录: |