Open BillWagner opened 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.
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.
@tugberkugurlu What about within the body of an async
method?
@sharwell I think that case qualifies as a legit use of this analyzer.
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.
Our VSTHRD002 analyzer does this.
Tasks should not block. Instead, they should be awaited so that execution can continue.