CultureInfo and Threads

  • Thread starter Thread starter schaf
  • Start date Start date
S

schaf

Hi NG!
My situation:
I call a function on a related system and this function call results in
a fired event, handled in my app. I recognized that the handle method
runs in his own thread and this thread has his own culture settings. I
guess that's because of the delegate which belongs to the related
system !??!
Ok i have invoked the event and now every thing is running in my
thread.
Now I have a question to CultureInfo and Threads.
My app runs on a MS OS with cultureInfo (en-US). If i start a thread T1
and set the CultureInfo to fr-FR and this thread T1 starts a new thread
T2, which CultureInfo would be set for T2 ? en-US from the system or
fr-FR from the parent thread ? Do I have some possibilities to change
this behavior ?

Thanks
 
schaf,

The new thread should pick up the culture of the parent thread.

Of course, wiring up a simple test should confirm or deny this.

As for changing it, you just have to get a reference to the Thread and
set the CurrentCulture property.

Hope this helps.
 
Nicholas Paldino said:
The new thread should pick up the culture of the parent thread.

Of course, wiring up a simple test should confirm or deny this.

As for changing it, you just have to get a reference to the Thread and
set the CurrentCulture property.

Here's the kind of test program Nick was talking about - which actually
shows that it *doesn't* pick up the current culture (although I agree
that it would make sense for it to do so). It also gives an example of
changing the CurrentCulture:

using System;
using System.Threading;
using System.Globalization;

class Test
{
static void Main()
{
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture ("fr");
Thread.CurrentThread.Name = "Main";
Foo();
Thread t = new Thread(Foo);
t.Name = "Other";
t.Start();
}

static void Foo()
{
Console.WriteLine ("{0}: {1}",
Thread.CurrentThread.Name,
Thread.CurrentThread.CurrentCulture);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top