Search code examples
c#parallel-processingtimeoutbarrier

C# Barrier timeout


I'm running some tasks in parallel, normally 4 at a time. For one test I need a barrier, so they are synchronized at that point.

The Barrier is then configured like new Barrier(4);. The issue is that sometimes, an exception might happen, which could lead the task to stop at a certain point and no longer reaches the Barrier.

This would make the Barrier wait eternally, how can I solve this? Is it possible to configure a Timeout to release the Barrier, and test the ones that have reached it until that moment?

This question is related to this post


Solution

  • If I understand you correctly, you want 3 tasks to continue even if the 4th task has failed. In this case you can use SignalAndWait(Int32) overload to wait for the other participants only for the specified period of time.