Hi,
I'm am developing windows service project in VS 2017 which inludes 2 resx files: RsysRes.resx (default language) and RsysRes.en.resx. Both files are compiled as embedded resource.
Service does some job and when the job is done an email is sent to user or if some error occurs, error is logged into log text file.
Problem is when the service is started and CurrentUICulture = "en-US" (different from default language) and the job is done or error occurs, email message text or error message text should be in english but it is not, message is in default language.
I have LoadSettings() method in which Thread.CurrentThread.CurrentUICulture is set and it works ok. LoadSettings() is called in OnStart():
private string _lang;
System.Timers.Timer _timer = new System.Timers.Timer();
protected override void OnStart(string[] args)
{
try
{
LoadSettings();
string msg = string.Format("******* Reportsystem service started at: {0} *******", DateTimeExt());
CreateLogFile(msg, null, null, true);
}
catch (Exception ex)
{
_fatalError = true;
CreateLogFile(ex.Message, null, null, true);
Util.SendEmail_Status(ex.Message, _serviceSendsNotificationEmailTo);
}
if (_fatalError)
return;
_timer.Elapsed += new ElapsedEventHandler(this.OnElapsedTime);
_timer.Interval = 50000; //miliseconds
_timer.Enabled = true;
}
private void LoadSettings()
{
try
{
_lang = GetSettingsValue("LANG_BASE");
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(_lang);
// some other code
}
catch (Exception)
{
throw;
}
}
Values from resx files are retrieved as follows:
RSysRes.ResourceManager.GetString("summary");
In case of "en-US" ResourceManager should retrieve a value from RSysRes.en.resx file but the value is retrieved from RSysRes.resx.
Does anyone know what i'm doing wrong and how to make it work?
I appreciate any help.