lewis
lewis

Reputation: 492

Set CultureInfo for new threads from .NET Windows Service

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?

Upvotes: 2

Views: 1765

Answers (1)

Ailis
Ailis

Reputation: 177

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.

Upvotes: 1

Related Questions