I have performed a huge refactoring and I converted hundreds of Web API methods that from sync to async.
The problem is that now I have a lot of problems! Mainly because every caller of those methods should use the await keyword in every call.
The compiler has been useful, since most of the cases can be detected an fixed watching compiler errors/warnings, but there are silent cases when the compiler doesn't help.
For instance, in situations like this:
public async Task<Item> Example()
{
return new Item
{
Property = GetName();
};
}
private Task<string> GetName()
{
return Task.FromResult("Hello");
}
class Item
{
public object Property { get; set; }
}
Please, notice that the GetName
method isn't awaited, but the compiler won't complain nor emit any warning, because Property is of type object
and will accept anything (and that includes a Task
)
Is there any way to detect such un-awaited Task? Maybe an extension or a nice trick?