I have an async WebForms Page (.Net Framework 4.62) and I set the culture in the InitializeCulture
method, see below code.
I run some async operation by using the page RegisterAsyncTask
method.
The callback for the async operation (on another thread) loses the CurrentCulture
. The DefaultThreadCurrentCulture
have the right culture, but CurrentThread.CurrentCulture
is wrong. Did anyone solve the same trouble?
protected override void InitializeCulture()
{
Thread.CurrentThread.CurrentUICulture = currentCulture;
Thread.CurrentThread.CurrentCulture = currentCulture;
CultureInfo.CurrentCulture = currentCulture;
CultureInfo.CurrentUICulture = currentCulture;
CultureInfo.DefaultThreadCurrentCulture = currentCulture;
CultureInfo.DefaultThreadCurrentUICulture = currentCulture;
}
This trouble with lost culture began when I updated .Net Framework from 4.51 to 4.62. With WebForms page setting async
set to true, I have the default thread culture in the PreRenderComplete
event instead of the current culture set in the InitializeCulture
method.
It does not depend on whether I register some async operation or not. I know that async operation callback can be on another thread, but I see a bad culture before an async operation is executed, at the start of the async method.
The trouble after the async method execution can be solved with some custom synchronization context, atd...