79761069

Date: 2025-09-10 16:24:22
Score: 1
Natty:
Report link

Why is this code different?

The difference is when and where you create the task. There is a big difference between

... Task.Run(async () => await CreateTheTaskInsideTheLambda().ConfigureAwait(false))...

and

var theTask = CreateTheTaskOutsideOfLambda();
... Task.Run(async () => await theTask.ConfigureAwait(false))...

The lambda is executed on the thread pool, so CreateTheTaskInsideTheLambda() cannot catch any ambient SynchronizationContext. .ConfigureAwait(false) here changes nothing, it's not necessary.

CreateTheTaskOutsideOfLambda() on the other hand may catch SynchronizationContext on the first await inside, if that await doesn't have .ConfigureAwait(false). This may cause a deadlock.
Again .ConfigureAwait(false) in Task.Run(async () => await theTask.ConfigureAwait(false)) changes nothing.

Reasons:
  • RegEx Blacklisted phrase (0.5): Why is this
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Why is this code
  • Low reputation (0.5):
Posted by: Sinus32