Warning message about await in catch - by Levente0xFFFE

Status : 

 


1
0
Sign in
to vote
ID 788485 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 5/23/2013 4:25:05 AM
Access Restriction Public

Description

I get the following warning message in an async method:

"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."

After I write await before the method call I get:
"Cannot await in the body of a catch clause"

This warning message shouldn't be allowed in a catch block, unable to use treat warnings as errors feature.

Sign in to post a comment.
Posted by Alex [MSFT] on 7/12/2013 at 9:42 AM
Thanks for reporting this issue you've encountered with Visual Studio!

We agree that the warning message telling you to await is unfortunate when it occurs inside a catch block. However, we would not want to completely remove this warning, as it still serves to remind you within catch blocks when you've accidentally called an async method and may not have realized that your code will continue running before it completes. It's true that you cannot await it, but you could call .Wait() if you knew that it was OK to block on the current thread, or assign the resulting Task to a dummy variable if you know that it's OK to "fire and forget" this async operation and move on. While your options are more limited inside a catch block, it's still important to make such a decision explicitly.

We could explore replacing this warning with a more nuanced warning inside catch blocks, but that unfortunately falls below the bar for the next release of Visual Studio at this point.

Alex Turner
Senior Program Manager
Visual Basic and C# Compiler
Posted by Microsoft on 5/23/2013 at 11:45 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Macy [MSFT] on 5/23/2013 at 4:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)