I want to run a Task and remove it from a list once it is completed. More precisely, I want to remove the ContinueWith task, not the task itself, see below:
void RunTask(Action someAction)
{
var task = new Task(someAction);
Task? continueWithTask = null;
continueWithTask = task.ContinueWith(_ =>
{
_runningTasks.Remove(continueWithTask); // <- Is there a better/safer way to access the continueWithTask?
});
_runningTasks.Add(continueWithTask);
task.Start();
}
My question here is really about the way of accessing the continueWithTask in the ContinueWith action itself, because here the compiler warns on the fact that continueWithTask might be null (even if it isn't at runtime).