安装Windows更新KB3136000后,WPF应用程序在更改CurrentThread文化时会出现意外情况。
在WPF中执行以下代码(以.NET Framework 4.6.1为目标)
public MainWindow()
{
var defaultCultureInfo = string.Format("Default Culture: Culture: {0}, UICulture: {1}, ThreadID: {2}",
Thread.CurrentThread.CurrentCulture, Thread.CurrentThread.CurrentUICulture, Thread.CurrentThread.ManagedThreadId);
var culture = new CultureInfo("hu-HU");
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
var newCultureInfo = string.Format("New Culture (Should be hu-HU): Culture: {0}, UICulture: {1}, ThreadID: {2}",
Thread.CurrentThread.CurrentCulture, Thread.CurrentThread.CurrentUICulture, Thread.CurrentThread.ManagedThreadId);
System.Diagnostics.Trace.WriteLine(defaultCultureInfo);
System.Diagnostics.Trace.WriteLine(newCultureInfo);
InitializeComponent();
}
给出以下结果(德语是我的操作系统语言):
Default Culture: Culture: de-DE, UICulture: de-DE, ThreadID: 8
New Culture (Should be hu-HU): Culture: de-DE, UICulture: de-DE, ThreadID: 8
在定位.NET Framework 4.5时执行相同的代码会得到以下(正确的)结果:
Default Culture: Culture: de-DE, UICulture: de-DE, ThreadID: 8
New Culture (Should be hu-HU): Culture: hu-HU, UICulture: hu-HU, ThreadID: 8
在面向.NET Framework 4.6.1时,在控制台应用程序中执行类似的代码也会得到正确的结果。
在安装KB3136000后,将WPF应用程序的文化更改为与操作系统文化不同的文化时,似乎会出现此问题。
有没有人遇到过类似的问题?有没有办法在没有Microsoft帐户的情况下向Microsoft报告问题。我们在Connect Microsoft上尝试的过程在第一步后失败了: "您无权提交此连接的反馈。"
编辑:
启动新线程也有奇怪的行为(.NET 4.6.1,WPF)。将以下代码添加到上面的代码中:
var thread = new Thread(new ThreadStart(() =>
{
Console.WriteLine("In Thread: Culture: {0}, UICulture: {1}, {2}", Thread.CurrentThread.CurrentCulture, Thread.CurrentThread.CurrentUICulture, Thread.CurrentThread.ManagedThreadId);
}));
thread.Start();
thread.Join();
Console.WriteLine("After Thread-Execution: Culture: {0}, UICulture: {1}, {2}", thread.CurrentCulture, thread.CurrentUICulture, thread.ManagedThreadId);
结果:
In Thread: Culture: de-DE, UICulture: de-DE, 10
After Thread-Execution: Culture: hu-HU, UICulture: hu-HU, 10