我说得对忽视对于缺少等待此异步调用编译器警告? [英] Am I right to ignore the compiler warning for lacking await for this async call?

查看:138
本文介绍了我说得对忽视对于缺少等待此异步调用编译器警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已被异常时在我的地铁申请的一部分发生触发了下面的方法

I have the following method that is triggered when an exception occurs in a part of my Metro application

void Model_ExceptionOccured(Exception ex)
{
    var dlg = new Windows.UI.Popups.MessageDialog("An exception occured during verification: " + ex.Message, "Exception");
    dlg.ShowAsync();
}

在'dlg.ShowAsync() - 电话是异步的,但我不在乎等待结果。编译器为它警告,虽然:

The 'dlg.ShowAsync()'-call is asynchronous, but I don't care to wait for the result. The compiler generates a warning for it though:

因为这个呼叫没有等待,呼叫结束之前,在当前的方法继续执行。考虑应用'等待'操作的调用的结果。

我应该关心?有什么理由我应该添加的await关键字,而不是摆脱警告其他?

Should I care? Is there any reason I should add the await keyword, other than to get rid of the warning?

推荐答案

根据下面的链接,通过alexm给出的答案是不正确的。例外是不是期待已久的将丢失一个异步调用时抛出。要摆脱这种警告,你应该分配异步调用一个变量的任务返回值。这将确保您可以访问任何抛出的异常,这将在返回值来表示。

According to the below link, the answer given by alexm is not correct. Exceptions thrown during an async call that is not awaited will be lost. To get rid of this warning, you should assign the Task return value of the async call to a variable. This ensures you have access to any exceptions thrown, which will be indicated in the return value.

http://msdn.microsoft.com /en-us/library/hh965065(v=vs.110).aspx (VB.NET)

http://msdn.microsoft.com/en-us/library/ hh873131.aspx (C#)

这篇关于我说得对忽视对于缺少等待此异步调用编译器警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆