What does the Asp.net Identity WithCurrentCulture () task extension do and why?

I am trying to understand the internal workings of the Identity Asp.net system and saw that all calls asyncseem to use the task extension WithCurrentCulture(). I looked at the source code of this extension and I can’t understand what it does or why.

From the documentation

Configures awaiter, which is used to wait for this task, to avoid sorting the continuation in the original context, but preserve the current UI culture and culture.

Can anyone shed some light on him?

+4
source share
2 answers

Thread.CurrentCulture Thread.CurrentUICulture , , .

Windows. , , , Thread.CurrentCulture . , ConfigureAwait(false), await , await. , CurrentCulture .

Thread.CurrentThread.CurrentCulture = someCulture;
await SomeTask().ConfigureAwait(false);

bool equal = Thread.CurrentThread.CurrentCulture == someCulture; // Might be false!

, await, WithCurrentCulture(). , ConfigureAwait(false), .

Thread.CurrentThread.CurrentCulture = someCulture;
await SomeTask().WithCurrentCulture();

bool equal = Thread.CurrentThread.CurrentCulture == someCulture; // Will be true

, OMIT ConfigureAwait(false) WithCurrentCulture(), await , , . WithCurrentCulture() , , .

: , CultureInfo.DefaultThreadCurrentCulture CultureInfo.DefaultThreadCurrentUICulture.

+6

, . , , ..

0

All Articles