I have the following requirements:
Below is my code but it is not working. Is it possible that I want to launch a task when another task is cancelled?
Task.WhenAny(runTask1(), runTask2()).ContinueWith((t0) =>
{
runTask5();
if (runTask5().Status == TaskStatus.Canceled)
{
runTask4();
}
});
_ = await Task.WhenAny(runTask1(), runTask2());
try
{
await runTask5();
}
catch(OperationCancelledException ex)
{
await runTask4();
}
You can await
Task
s inside catch
and finally
blocks since C# 6.