c# - Task.WaitAll hangs with async/await tasks -
i must missing obvious, deadlock on synchronizationcontext
, not see why happens, , not understand how can avoid it...
so, application azure workerrole (essentially, far understand, usual windows app without ui). in application, trying parallel execution of number of tasks, , schematic version of code this:
private async task dojob() { await someiooperation(); } public void methodexecutedbyworkerroleinaninfiniteloop() { log("start"); task.waitall(dojob(), dojob(), dojob()); log("end"); }
my idea here operating default synchronizationcontext
here, should avoid deadlock have in similar situation in, example, asp.net.
however, sometimes execution hangs - start logged, end not days until restart worker role. naturally,there no way dojob running long. oddly, not happen after worker role starts - may take days or weeks of normal operation until hangs.
i simplifying code - maybe important happens in someiooperation
- feel obvious related synchronizationcontext
misuse.
will someiooperation.configureawait(false)
help? cannot test it, because not know if working because issue fixed, or hang after few more days.
ideas?
you fall in deadlock on synchronizationcontext. use whenall
instead of waitall
:
public async task methodexecutedbyworkerroleinaninfiniteloop() { log("start"); await task.whenall(dojob(), dojob(), dojob()); log("end"); }
and work.
Comments
Post a Comment