DotNetAnalyzers / AsyncUsageAnalyzers

Now superseded by Microsoft/vs-threading
https://github.com/Microsoft/vs-threading
Other
121 stars 18 forks source link

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

Open BillWagner opened 9 years ago

BillWagner commented 9 years ago

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

sharwell commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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

tugberkugurlu commented 9 years ago

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

tmaczynski commented 8 years ago

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 commented 6 years ago

Our VSTHRD002 analyzer does this.