Using revocation with asynchronous tasks

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

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

I would like to register a common CancellationToken with this task, so that if the token is canceled before this Async task starts, it will not be called.

thank

+3
source share
2 answers

So, after thinking about this, I think that canceling the Async task does not make sense, since the Begin part will be called inline, which is immediately in the calling thread.

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

(, - -), TaskCompletionSource, : http://msdn.microsoft.com/en-us/library/ee622454.aspx

, , , -.

+2

, Async .

, ( ), , , TaskFactory, OrderedTaskScheduler ( ). OrderedTaskScheduler http://archive.msdn.microsoft.com/ParExtSamples/Release/ProjectReleases.aspx?ReleaseId=4179

,

0

Source: https://habr.com/ru/post/1769490/


All Articles