I try to implement multicultural application where users able to change language, date format and etc. I wrote core but it returns Exception: System.InvalidOperationException: Instance is read-only.
switch (culture)
{
case SystemCulture.English:
Thread.CurrentThread.CurrentCulture = new CultureInfo(CultureCodes.English);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(CultureCodes.English);
break;
//another cultures here
}
switch (cultureFormat)
{
case SystemDateFormat.European:
var europeanDateFormat = CultureInfo.GetCultureInfo(CultureCodes.Italian).DateTimeFormat;
Thread.CurrentThread.CurrentCulture.DateTimeFormat = europeanDateFormat;
Thread.CurrentThread.CurrentUICulture.DateTimeFormat = europeanDateFormat;
break;
//another cultures here
}
I found some information on internet and i have to use new instance object of my culture, i changed my code just adding:
CultureInfo myCulture;
switch (culture)
{
case SystemCulture.English:
myCulture= new CultureInfo(CultureCodes.English);
break;
}
and bellow, out of switch :
Thread.CurrentThread.CurrentCulture = cultureInfo;
I'm not familiar with Threads and i'm not sure if i used is correctly. Could you please suggest me how to do this it right way ?