views:

25

answers:

1

Is there a way to cancel an Async System.Threading.Tasks.Task? i.e.

Task.Factory.FromAsync(
    client.BeginCallWebService, 
    client.EndCallWebService, 
    "param1", 
    null);

I would like to register a shared CancellationToken with this task so that if the token is cancelled before this Async task is invoked, it won't be invoked.

Thanks

A: 

So, having put some more thought into this I think cancelling an Async task makes no sense as the Begin part will be invoked 'inline' that, is right away on the calling thread.

Therefore there is no need to support cancellation in this way.

If you wanted to actually abort a processing call (e.g. to a web service or using web client) you could implement a TaskCompletionSource approach instead as documented here: http://msdn.microsoft.com/en-us/library/ee622454.aspx

Sorry to answer my own question, I'm guessing that's a bit of no-no.

ConfusedNoob