And why can't you just use
System.Threading.Thread.Sleep(10000);
in the
while (!cancellationToken.IsCancellationRequested)
Block?
As far as how to wait for the GetRssItems you can use the ContinueWith to call a 'finish' or 'next'
I have this
private void StartTask(long taskId, Action workToDo)
{
try
{
Task task = new Task(workToDo);
this.taskIdList.Add(taskId);
task.ContinueWith(result => this.taskIdList.Remove(taskId));
task.Start();
this.EventLog.WriteEntry("Started Task Id " + taskId.ToString() + "\n", System.Diagnostics.EventLogEntryType.Information);
Debug.WriteLine("Task List Count:" + this.taskIdList.Count.ToString());
}
catch (Exception ex)
{
this.EventLog.WriteEntry(" Exception thrown. Task Id:" + taskId.ToString() + "\n");
this.SetTaskException(taskId, "Exception thrown performing task.", ex);
}
}
When the thread ends, it comes back and removes itself from the list of active threads
task.ContinueWith(result => this.taskIdList.Remove(taskId));
you can do what ever you want at that point.