I'm having trouble with this. I've got "WorkItem" which has a method DoWork. WorkItem can have dependencies which MUST complete before it does, otherwise it throws an exception.
Here's a diagram, where each item (A, B, C, etc.) is a WorkItem. The first items off the rank should thus be A, B, E, as they have no dependencies.
So I throw "G" to DoWorkForTask, but my exception throws itself, proving that, say, A and B haven't completed before C runs. The whole tiny project is zipped up here.
private void DoWorkForTask(WorkItem item)
{
// NOTE: item relies on Dependents to complete before it proceeds
Task.Factory.StartNew(() =>
{
foreach (var child in item.Dependents)
{
Task.Factory.StartNew(child.DoWork, TaskCreationOptions.AttachedToParent);
if (child.Dependents.Count > 0)
DoWorkForTask(child);
}
item.DoWork();
}, TaskCreationOptions.AttachedToParent);
}
Note that I've read this thread and it does not solve the issue.