I've just stumbled across a rather dangerous scenario while migrating an ASP.NET application to the async/await model.
The situation is that I made a method async: async Task DoWhateverAsync(), changed the declaration in the interface to Task DoWhateverAsync() and hoped that the compiler would tell me where the code now is wrong, via that Warning. Well, tough luck. Wherever that object gets injected via the interface, the warning doesn't happen. :-(
This is dangerous. Is there any way to check automatically for non-awaited methods that return tasks? I don't mind a few warnings too many, but I wouldn't want to miss one.
Here's an example:
using System.Threading.Tasks;
namespace AsyncAwaitGames
{
// In my real case, that method just returns Task.
public interface ICallee { Task<int> DoSomethingAsync(); }
public class Callee: ICallee
{
public async Task<int> DoSomethingAsync() => await Task.FromResult(0);
}
public class Caller
{
public void DoCall()
{
ICallee xxx = new Callee();
// In my real case, the method just returns Task,
// so there is no type mismatch when assigning a result
// either.
xxx.DoSomethingAsync(); // This is where I had hoped for a warning.
}
}
}


stringand attempt to use it as astring, but really it's aTask<string>, the compiler will tell me about that. (Doesn't help withvoid/Taskones though, I guess.)awaitis a point in the program where the continuation of the await logically requires the completion of the task. The code before your change did not logically require the completion of the task, so why should it now after your change? What wrongness was introduced?public void DoCall() { ICallee xxx = new Callee(); xxx.DoSomething();}(good). After:public void DoCall() { ICallee xxx = new Callee(); xxx.DoSomethingAsync();}(bad). Good:public void DoCall() { ICallee xxx = new Callee(); await xxx.DoSomethingAsync();}