My application lets the user create "Task" objects from the UI and set their order of executions. From there, when the user click "run" all of the Tasks (by order) are sent to a class that suppose to chain and run them. The class is as follow:
public class MaintenanceTask{ private CancellationTokenSource m_CancellationTokenSource; private Task m_BatchTask; public MaintenanceTask() { m_CancellationTokenSource = new CancellationTokenSource(); } public void AddTaskIdent(TaskIdentBase ident) { Task newTask = ident.Create(m_CancellationTokenSource.Token); if (m_BatchTask == null) m_BatchTask = newTask; else m_BatchTask.ContinueWith(prev=>newTask); } public void Run() { if (m_BatchTask != null) m_BatchTask.Start(); }}
The AddTaskIdent is recieving a base class that knows how to create the Task object.My problem is that calling Run() start the first task that was sent to the class. It runs it until finished by no other task following it gets to run.It's just stops after the first task is done.
Am I missing something with the ContinueWith mechanism ?