I\'m fairly new to async/await programming and sometimes I feel that I understand it, and then all of a sudden something happens and throws me for a loop.
I\'m tryin
You just need to change the DoStuffAsync task little bit, as below.
private async Task DoStuffAsync(CancellationTokenSource c)
{
return Task.Run(()=> {
int ret = 0;
// I wanted to simulator a long running process this way
// instead of doing Task.Delay
for (int i = 0; i < 500000000; i++)
{
ret += i;
if (i % 100000 == 0)
Console.WriteLine(i);
if (c.IsCancellationRequested)
{
return ret;
}
}
return ret;
});
}