本文介绍了多线程WPF应用程序设置线程CultureInfo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理多线程wpf应用程序.为了执行全球化,我尝试将当前线程的(主线程)区域性设置为app.xaml.cs中的不变区域性,以便使应用程序域中的所有C#对象都能处理区域性不变信息.但是,当使用许多线程来调用工作线程时,就会出现问题,这些线程的区域性默认为我不想要的OS文化设置.帮助我找出创建的工作线程从主线程继承CultureInfo的方式

I'm working on a multithreaded wpf application. To perform globalization i tried to set the current thread's(main thread) culture to invariant culturee in app.xaml.cs, So that all C# objects in app domain works on culture invariant info. But the problem arises when many threads comes to usage the worker threads invoked, those thread's culture are defaulted to OS Culture settings which i don't want. Help me in finding out a way where the worker threads created inherits the CultureInfo from main thread

推荐答案

我认为没有办法将区域性分配给整个AppDomain.最好的选择可能是使用助手类来实例化线程.

I don't think there is a way to assign the culture to the entire AppDomain. Your best option might be to use a helper class to instantiate the threads.

class ThreadHelper
{
    public static Thread getThread(ThreadStart start, int maxStackSize)
    {

        Thread t = new Thread(start,maxStackSize);
        t.CurrentCulture = new System.Globalization.CultureInfo(3081);
        return t;
    }
}

这篇关于多线程WPF应用程序设置线程CultureInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 01:45