I'm using the resource manager to load resources based on threadUI culture in an ASP.NET MVC 5 application.i set thread culture in Application_AcquireRequestState Event, current culture saves per user, it's loaded by a web server in DataBase as below Code:
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
string languageName = default(string);
CultureInfo ci = default(CultureInfo);
if (!User.Identity.IsAuthenticated)
{
languageName = Request.RequestContext.HttpContext.Session["_culture"] == null ?
Helper.ApplicationInformation.AppCulture.Name :
Request.RequestContext.HttpContext.Session["_culture"].ToString();
ci = CultureInfo.GetCultureInfo(languageName.ToUpper());
}
else
{
ci = CultureInfo.GetCultureInfo(Helper.User.Preferences.Language.Name);
}
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
Bridge.Resources.Global.Culture = ci;
Bridge.Resources.Login.Culture = ci;
Bridge.Resources.Search.Culture = ci;
Bridge.Resources.Workspace.Culture = ci;
}
it's happening when setting the culture in a different thread, actually when 2 user or more changes languages at the same time,
I think there is a RaceCondition problem in resource manager that cause loading resources with invalid UI Culture for the current thread
I did a research about this and find the following relevant links:
ASP.Net MVC resource files are sometimes incorrectly loaded by the ResouceManager
ASP.NET Resource Manager RaceCondition in Multilingual Application
I try to download example for multi-language but it also happens, I download from the following link:
add 'ThreadSleep(4000)' in action:index control:Home to reproduce this issue.
I did everything mentioned but nothing work. what can I try to make resources to work consistently?
thanks.