Home Dashboard Directory Help
Search

Warning message about await in catch by Levente0xFFFE


Status: 

Closed


1
0
Sign in
to vote
Type: Bug
ID: 788485
Opened: 5/23/2013 4:25:05 AM
Access Restriction: Public
2
Workaround(s)
view
0
User(s) can reproduce this bug

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.

Details
Sign in to post a comment.
Posted by Microsoft 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 Microsoft 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)
Sign in to post a workaround.
Posted by Microsoft on 7/12/2013 at 9:43 AM
Call .Wait or assign the resulting Task to a dummy variable.
Posted by Levente0xFFFE on 6/5/2013 at 5:25 AM
Add the warning to the suppress warnings list.
File Name Submitted By Submitted On File Size  
VsInfo.xml (restricted) 5/23/2013 -
UploadSummary-130523112502.xml (restricted) 5/23/2013 -