Is Task.Delay Worth Cancellation?

First of all, this whole issue is probably negligible performance-wise and should only be considered otherwise after testing in a real environment.

However if we dive in, Task.Delay creates a task that is completed after a certain interval. It does so by creating a new System.Threading.Timer (which implements IDisposable) that completes the promise task after the interval using a ThreadPool thread.

If you use Task.Delay "a lot" you can have a considerable amount of wasted resources hanging around long after they're useful. If you also add any continuations to the Task.Delay task with a delegate that captures any references they too will hang around with no reason.

So yes, it's safer to cancel the task instead of letting it run out, though probably not by much.


Task.Delay is worth cancelling when you care about the shutdown speed of your app.

One example is asp.net web applications.

When the server recycles your web-app (when it's being live-updated for example) it needs everything to end fast. If you have tasks waiting in the background, especially registered via QueueBackgroundObject or a similar technique, it might take a while for the app to shut down.