在控制面板中,我将区域和语言设置为法语(法国)
当我将我的应用程序作为控制台应用程序运行时,
Thread.CurrentThread.CurrentCulture
返回法语
但是当我将它作为 Windows 服务运行时,它返回不变的文化或英语(美国)
有没有办法解决这个问题?
在控制面板中,我将区域和语言设置为法语(法国)
当我将我的应用程序作为控制台应用程序运行时,
Thread.CurrentThread.CurrentCulture
返回法语
但是当我将它作为 Windows 服务运行时,它返回不变的文化或英语(美国)
有没有办法解决这个问题?
该服务可能以拥有自己文化的用户身份运行。
为什么不在开始服务时设置文化
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");
If your Windows Service is running under the SYSTEM account or other account without a
profile it will use the settings defined under the
"HKEY_USERS/.DEFAULT/Control Panel/International" registry key.
You can change these values from "Control Panel / Regional and Language Options / Advanced"
by checking the checkbox "Apply all settings to the current user account and to the default
user profile".
我通常使用前一种技术,因为我只需要为特定服务而不是整个操作系统更改它。
.NET 4.5
添加了CultureInfo.DefaultThreadCurrentCulture
,CultureInfo.DefaultThreadCurrentUICulture
我建议尽早设置它,它应该可以解决您的问题。这将改变当前线程文化和创建的所有线程。