Given followingNo problem ! The task running MyCanceledMethod is perfectly canceled and I don't get to see the *****.Code:static void Main(string[] args)
{
try
{
CancellationTokenSource cts = new CancellationTokenSource();
Task t = Task.Factory.StartNew(() => MyCanceledMethod(cts.Token), cts.Token);
t.ContinueWith(x =>
{
Console.WriteLine("Canceled successfully !");
}, TaskContinuationOptions.OnlyOnCanceled);
cts.Cancel();
t.Wait();
}
catch { }
}
static void MyCanceledMethod(CancellationToken ct)
{
for (int i = 0; i < 5; i++)
{
Thread.Sleep(1000);
Console.Write('*');
}
}
Now if I were to start the task in this wayThat's with a lambda taking one not used parameter x instead of () , the task just doesn't get canceled :confused:Quote:
Task t = Task.Factory.StartNew(x => MyCanceledMethod(cts.Token), cts.Token);
Can anyone explain to me the relation between task delegate signature and the TaskContinuationOptions.OnlyOnCanceled not being respected ?