c# - 在 .NET 应用程序中在哪里设置默认区域性

标签 c# .net culture

我正在编写一个 WPF 应用程序,但在文化方面遇到了一些困难。

我想知道当没有明确设置值时,.NET 应用程序从哪里获取 CurrentThread.CurrentCulture 的值。它不是来自 Windows 区域性信息,因为我已将其从 en-US 更改为 en-GB,但在运行时没有注意到应用程序有任何变化。

请帮忙!

标记

最佳答案

来自 the fine manual :

See the CultureInfo.CurrentCulture property to learn how a thread's default culture is determined, and how users set culture information for their computers.

One laborious click later...

How a Thread's Culture Is Determined

When a thread is started, its culture is initially determined as follows:

  • By retrieving the culture that is specified by the DefaultThreadCurrentCulture property in the application domain in which the thread is executing, if the property value is not null.

  • By calling the Windows GetUserDefaultLocaleName function.

Note that if you set a specific culture that is different from the system-installed culture or the user's preferred culture, and your application starts multiple threads, the current culture of those threads will be the culture that is returned by the GetUserDefaultLocaleName function, unless you assign a culture to the DefaultThreadCurrentCulture property in the application domain in which the thread is executing.

For more information about how the culture of a thread is determined, see the "Culture and Threads" section in the CultureInfo topic.

I didn't budget for another click, but clicked anyway .

Culture and Threads

When a new application thread is started, its current culture and current UI culture are defined by the current system culture, and not by the current thread culture. The following example illustrates the difference. It sets the current culture and current UI culture of an application thread to the French (France) culture (fr-FR). If the current culture is already fr-FR, the example sets it to the English (United States) culture (en-US). It displays three random numbers as currency values and then creates a new thread, which, in turn, displays three more random numbers as currency values. But as the output from the example shows, the currency values displayed by the new thread do not reflect the formatting conventions of the French (France) culture, unlike the output from the main application thread.

请注意,它说当一个新的应用程序线程启动时。所以,鉴于你说:

It's not from the Windows culture info because I have changed that from en-US to en-GB without noticing any change in the application when running.

您可能想要查看 this answer .

关于c# - 在 .NET 应用程序中在哪里设置默认区域性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17567298/

相关文章:

c# - 连接到 RFID 阅读器时出错 : The maximum baud rate for the device is 8190

c# - 盒子内容 API : Is modified_at field of parent folder updated when deleting an item from folder?

c# - 如何将区域性更改为 .Net 中的 DateTimepicker 或日历控件

routing - 根据用户文化选择 routing.yml?

c# - DataGrid 具有 WPF 中第 n 级单元格的 DataGrid

c# - CultureInfo 和 ISO 639-3

c# - WCF 服务和单例

c# - 关于 C# 中的文件权限

c# - .net Tcp 服务器每隔几分钟接收一次大块字节

.net - WCF 服务自定义配置