2

I need to set CultureInfo for a Windows Service, written in C# 4.0. Trouble is in OS locale - it differs from my service's culture.

Because I am using .NET 4.0 (in .NET 4.5 I may change default culture for all new threads), my question is:

How can I handle creation of all new threads in my Windows Service, and set CultureInfo for them?

John Willemse
  • 6,608
  • 7
  • 31
  • 45
lewis
  • 482
  • 2
  • 10
  • 22
  • 1
    http://stackoverflow.com/questions/4894405/localize-windows-service might help – noobob May 06 '13 at 06:57
  • @noobob, in your link, topicstarter asks "how to add globalization resources to my app". I'm already have resources in my app, but I can't set CultureInfo. It causes wrong resource selection. – lewis May 06 '13 at 07:18
  • @noobob, I'm forgot adding localization resources to my WiX-generated msi. Thnx for help! – lewis May 09 '13 at 12:39

1 Answers1

1

A Windows Service doesn't mean a multiple-thread program. So you must create the thread in your code or your service is WCF service. If you create the thread by yourself, just set the culture of the new thread after created. If it's a WCF service, please see http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchmessageinspector.aspx. You need to implement the interface IDispatchMessageInspector and if there is a new request from the client (a new thread is might created) the method AfterReceiveRequest will be called, you could set CultureInfo within this method. If your Windows Service is not a WCF service, please show more information about it.

Ailis
  • 167
  • 4
  • Windows service has more than 1 thread. Even I'm set _Thread.CurrentThread.CurrentUICulture_ on service's "Main" method, my business logic code executes in other thread, with different _CultureInfo_. – lewis May 06 '13 at 07:39