Async code without waiting for completion Async code without waiting for completion asp.net asp.net

Async code without waiting for completion


After a morning of chasing this problem around I eventually discovered there was a path which could allow for the parent to bypass the await creating this problem. A quick refactoring to prevent this solved the problem.

In its most simple form the code causing the problem was along the lines of this:

var getDataTask = getData();if(some_condition == true) {    return some_object;}getDataTask.Wait();return getDataTask.result;

If some_condition == true the method would return without waiting for getDataTask to complete. Refactoring to stop that fixed it.