c# - Find awaitable methods in code with Visual Studio -
i have problem async
methods being called in code without await
in front of it. there way find awaitable methods not have await
?
edit - i'm particularly concerned scenario multiple async methods being called (ignoring return values), 1 has await
enough make visual studio not warn it.
if use resharper , turn solution-wide analysis on, methods returning tasks not being awaited have task portion of method signature grayed out due "return value not used." caveat here find methods not being awaited anywhere in solution; warning go away after 1 or more usages updated await (or use/reference task
).
if you're looking async methods don't contain await call (meaning don't need labeled async), resharper tell in similar fashion.
class aclass { public async void foo() //async grayed out { dosomethingasync(); console.writeline("done"); } public task<bool> dosomethingasync() //task<bool> grayed out { return task.run(() => true); } }
note not work if have code looks this:
class aclass { public async void foo() { bool b = dosomethingasync().result; console.writeline("done"); } public task<bool> dosomethingasync() { return task.run(() => true); } }
the async
keyword, if present, still flagged, means can figure out pretty task not being awaited, if calling method not marked async out of luck.
Comments
Post a Comment