You can invoke Task.WaitAnyexactly this task with an array. Then you can act in the status of the task, however the method returns. Code example:
using System;
using System.Threading;
using System.Threading.Tasks;
class Test
{
static void Main()
{
Task sleeper = Task.Factory.StartNew(() => Thread.Sleep(100000));
int index = Task.WaitAny(new[] { sleeper },
TimeSpan.FromSeconds(0.5));
Console.WriteLine(index);
var cts = new CancellationTokenSource();
Task cancellable = sleeper.ContinueWith(ignored => {}, cts.Token);
cts.Cancel();
index = Task.WaitAny(new[] { cancellable },
TimeSpan.FromSeconds(0.5));
Console.WriteLine(index);
Console.WriteLine(cancellable.Status);
}
}
, , "" , :)