Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

Calling Wait() (or any variation) instead of awaiting a task #1

Open
BillWagner opened this issue Nov 19, 2014 · 6 comments
Open

Calling Wait() (or any variation) instead of awaiting a task #1

BillWagner opened this issue Nov 19, 2014 · 6 comments

Comments

@BillWagner
Copy link

Tasks should not block. Instead, they should be awaited so that execution can continue.

@sharwell
Copy link
Member

Definitely an item of interest.

My instinct is this would be a warning when it occurs within an async method, and an information-level diagnostic elsewhere.

Checking the Result property can do this as well, but it will be very hard to know whether a particular access to the Result property is problematic or not. I'll have to think much more about this.

@tugberkugurlu
Copy link

This should never give a diagnostic message as there are quite a lot of places where you cannot run asyncronous code such as ASP.NET MVC child actions, Main method, etc.

@sharwell
Copy link
Member

@tugberkugurlu What about within the body of an async method?

@tugberkugurlu
Copy link

@sharwell I think that case qualifies as a legit use of this analyzer.

@tmaczynski
Copy link
Contributor

I will gladly implement initial version of this diagnostic once #50 is reviewed. I think that thanks to stuff I learned working on #50, coding this diagnostic should be quite simple.

To be on a safe side, I will find all usages of Wait() in async methods, async anonymous functions or async anonymous methods. Later, we can iterate and refine this diagnostic.

@AArnott
Copy link

AArnott commented May 2, 2018

Our VSTHRD002 analyzer does this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants