DEV Community


Discussion on: Async/Await easy cancellation in c#

gonyoda profile image
John Gonyo

A word of caution. This only cancels the await, it does not cancel the running task. Any additional code inside the awaited task will continue to execute.

Instead, you should add and pass a cancellation token to the awaited method so that the task itself is also cancelled.

That is, Task.Delay (and almost all other awaitable methods) accept(s) a cancellation token to cancel the delay before the time out expires.

alialp profile image
Ali Alp Author

thanks bro :) Very important point you have mentioned
I have updated the post to be more clear about the IO bound operations.
good examples will be web requests or waiting on TcpClient stream and ...