更改Windows服务作为LocalSystem运行的默认区域性 [英] Changing default culture for windows service running as LocalSystem

查看:259
本文介绍了更改Windows服务作为LocalSystem运行的默认区域性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的管理员意外地将运行.NET Windows服务的服务器迁移到Windows 2008(由于某些旧应用程序)。它在LocalSystem帐户下运行。目标框架是.NET Framework 4客户端配置文件。

Our admins unexpectedly migrated a server where my .NET windows service runs (to Windows 2008 ... because of some old apps). It is running under LocalSystem account. The target framework is .NET framework 4 Client Profile.

在我的服务中,方法 DateTime.Parse 现在抛出无效格式异常。

In my service the method DateTime.Parse now throws invalid format exception.

当我添加到 OnStart

Thread.CurrentThread.CurrentCulture = new CultureInfo("cs-CZ", false);

它会变得更好,但是在某些方法上还是失败了,可能在不同的雷达上运行。

it gets better, but still in some methods it fails, probably running in different therads.

如何配置服务器或更改程序以使所有线程都具有适当的文化?

How to configure the server or change the program to make all threads be created with proper culture?

推荐答案

从Microsoft.NET Framework 4.5及更高版本开始,您可以使用

Starting with Microsoft.NET Framework 4.5 and higher, you can use

var culture = CultureInfo.CreateSpecificCulture("cs-CZ");
CultureInfo.DefaultThreadCurrentCulture = culture;

这是在此处记录,但有一项警告,即它可能不适用于后续创建的线程。 Microsoft.NET Framework 4.6中包含了一个深刻的解决方案,在此处了解更多信息

This is documented here, with the caveat that it might not work for subsequently created threads. A profound solution is included with Microsoft.NET Framework 4.6, read more on it here.

这篇关于更改Windows服务作为LocalSystem运行的默认区域性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆