Re:C++20 has been approved
by pjmlp on Sunday September 06, 2020 @11:22AM
(#24391971)
I always end up with a couple of Task.Run() calls, because cannot change the complete call chain to deal with async/await.
[ Parent
| on HN ]
If you want to avoid changing the complete chain to Task, there’re workarounds.
You can block the caller thread waiting for the task. Deadlocks are possible with this approach due to synchronization context shenanigans, but they’re easy to fix, VS debugger is quite good at multithreading.
Another method, you can run whatever dispatcher on your main thread, in modern .NET that’s usually Dispatcher.PushFrame.
Also, if the async method returns no values, you don’t need to change the call chain, you just need to catch and handle exceptions.