This became strangely useful very quickly, when I encountered a problem similar to that described here. There are a couple of solutions to this question, but the least code churn is to simply make the code synchronous; however, if you do that by simply adding
to the end of the async calls, you’re very likely to result in a deadlock.
One possible solution is to wrap the call using the JoinableTaskFactory, in the following way:
var jtf = new JoinableTaskFactory(new JoinableTaskContext()); var result = jtf.Run<DataResult>(() => _myClass.GetDataAsync());
This allows the task to return on the same synchronisation context without causing a deadlock.