Revisiting Task.ConfigureAwait(continueOnCapturedContext: false)

When you’re dealing with asynchronous operations, the overhead of a thread switch is way too small to care about (generally speaking). The purpose of ConfigureAwait(false) is not to induce a thread switch (if necessary), but rather to prevent too much code running on a particular special context.

The reasoning behind this pattern was that “it helps to avoid deadlocks”.

And stack dives.

But I do think this is a non-problem in the general case. When I encounter code that doesn’t properly use ConfigureAwait, I just wrap it in a Task.Run and move on. The overhead of thread switches isn’t worth worrying about.

Leave a Comment