Skip to content

Work Dependency

ZjzMisaka edited this page Sep 24, 2025 · 10 revisions

If WorkOption.Dependents is set, the work will not start until all dependent works have completed execution.

WorkID id0 = powerPool.QueueWorkItem(() =>
{
    //Do something
});
WorkID id1 = powerPool.QueueWorkItem(() =>
{
    //Do something
});

powerPool.QueueWorkItem(() =>
{
    //Do something
},
new WorkOption()
{
    Dependents = new ConcurrentSet<WorkID>() { id0, id1 }
});

The thread pool will only save the information of works that have failed, and the record of failed works will be cleared when the thread pool enters the Idle state and is restarted, unless the PowerPoolOption.ClearFailedWorkRecordWhenPoolStart is set to false.
Normally, if a work begins execution but the work it depends on fail to complete, then it should not be allowed to execute.
If PowerPoolOption.ClearFailedWorkRecordWhenPoolStart is true, to prevent the loss of failure informations leading to the thread pool erroneously allowing the work to start, one can use PowerPool.EnablePoolIdleCheck to temporarily halt the thread pool's idle check until this work has been added to the thread pool.

If a circular dependency is detected when submitting the task, a CycleDetectedException will be thrown.

Clone this wiki locally