All, I have a generic method called TaskSpin
, in this method I launch a Task
with an ascociated continutation
public TaskSpin(Func asyncMethod, object[] methodParameters)
{
...
asyncTask = Task.Factory.StartNew<bool>(() =>
asyncMethod(uiScheduler, methodParameters));
asyncTask.ContinueWith(task =>
{
// Finish the processing update UI etc.
}
...
}
The problem is now that I want to run multiple methods using TaskSpin
, but I need to restrict the methods to run one-at-a-time. So foreach row in some DataGridView
I want to do something like
foreach (DataGridViewRow row in this.DataGridViewUrg.Rows)
TaskSpin(Run(DrgDataRowInfo(row.Index)));
However, in the above the TaskSpin
method will exit immediately causing TaskSpin
to spin off the next method on yet another thread. This is no good as the Run
method write to a common set of files. What is the best way to queue these jobs?