You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Analyzer proposal: remove redundant state machine #518
The await is not immediately returned (or not the last statement).
The await appears inside a try block.
A using var appears in the method, such that it will be disposed of prior to the returned Task being completed.
The type returned by the called async method is not exactly the same as the type returned from the calling async method. (e.g. Task<object> FooAsync() => BarAsync(); where BarAsync() returns Task<string> or ValueTask<object>.
Reacted by Dean Faizal, Marius Ungureanu, NN and FXZFun
I generally make this change manually and would appreciate the analyzer, but we should be aware that it changes the debugging experience by removing DoSomethingAsync from the call stack when the program is executing a continuation in SomethingElseAsync.
Removing async also disables the compiler warning saying a task should be awaited, so you'll definitely want to make sure that analyzer is working well before suggesting that async get removed.
ReSharper extensiosn ReCommended Extension and AsyncConverter suggesting to remove async/await.
This is indeed changes the stack trace but it is still a useful analysis.
Activity
mavasani commentedon Sep 17, 2019
Probably should offer 2 code fixes, with an additional comment around the try-catch for the more complex code fix?
drewnoakes commentedon Sep 17, 2019
I generally make this change manually and would appreciate the analyzer, but we should be aware that it changes the debugging experience by removing
DoSomethingAsyncfrom the call stack when the program is executing a continuation inSomethingElseAsync.sharwell commentedon Nov 23, 2019
Removing
asyncalso disables the compiler warning saying a task should be awaited, so you'll definitely want to make sure that analyzer is working well before suggesting thatasyncget removed.paulomorgado commentedon Dec 2, 2019
This is a performance optimization but it causes a change in the stack trace if an exception is thrown.
Check this post from Stephen Cleary (@StephenCleary):
Eliding Async and Await
NN--- commentedon Sep 30, 2020
ReSharper extensiosn ReCommended Extension and AsyncConverter suggesting to remove async/await.
This is indeed changes the stack trace but it is still a useful analysis.