dimanche 13 décembre 2015

Prevent Race Condition in ASP.NET Resource Class

As we know the static resource class share among multiple threads in asp.net,We have a CMS application uses resources for localizing strings but when the application is under load,Resource culture sometimes loads with invalid culture,for example in Views wee see that Thread.CurrentThread.CurrentUICulture is en-US but Resource.Culture is it-IT,It's about 3 month that we're working hard on this problem,in the last we had to set "Resource.Culture" in Application_AcquireRequestState and also Set it in OnResultExecuting but this is not the correct way and we see that resources in Layouts yet will be invalid sometimes under load.This is our code to set culture in Application_AcquireRequestState

var cultureInfo = new CultureInfo(lang);
var culture = CultureInfo.CreateSpecificCulture(cultureInfo.Name);
culture.DateTimeFormat.AMDesignator = "AM";
culture.DateTimeFormat.PMDesignator = "PM";
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
Monitor.Enter(Lockobj);
try
{
    Resources.App_GlobalResources.Resource.Culture = culture;
}
finally
{
    Monitor.Exit(Lockobj);
}

these are some threads that others had problem like this
ASP.Net MVC resource files are sometimes incorrectly loaded by the ResouceManager

http://ift.tt/1NNJAoi

Special thanks to Any one can help around this

Aucun commentaire:

Enregistrer un commentaire