C# BackgroundWorker's culture

前端 未结 6 894
情歌与酒
情歌与酒 2021-02-07 04:28

I woudl like to set the culture for my whole application. I tried the following :

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(wanted         


        
6条回答
  •  太阳男子
    2021-02-07 04:52

    I know the topic is old but I found myself in a "thread with OS culture" problem.

    I solved it so: as the BackgroundWorker is in a UserControl (it would be valid if it is in a Form and so on...) I set a field in the UserControl (or Form) when it is constructed. In the DoWork event handler I use this field in my operations. Here the code:

        /// 
        /// Culture in which the GUI creates the control.
        /// 
        private readonly CultureInfo _currentCulture;
    
        /// 
        ///     Default constructor.
        /// 
        public MyControl()
        {
            InitializeComponent();
            _currentCulture = CultureInfo.CurrentUICulture;
        }
    
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            ExampleClass.DoCultureDependentOperation(_currentCulture);
        }
    

提交回复
热议问题