473,322 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

CultureInfo and Threads

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

Sep 14 '06 #1
3 3724
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 [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"schaf" <sc***@2wire.chwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
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

Sep 14 '06 #2
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.comwrote:
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);
}
}
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 14 '06 #3
Hi All!
You are right. I have found the following sentence in this article.

Sentence:
Each thread inherits the default Windows culture unless you change it
by accessing the current thread through services provided by the
System.Threading namespace

Article:
http://msdn.microsoft.com/msdnmag/is...2/06/Internat/

Thanks and regards
Marcel
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);
}
}
Sep 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: chadb | last post by:
Basic scenario -Winforms client calling an asp.net web service on Windows X Problem: When I perform an async web service call from a winform client, my Thread.CurrentCulture and...
2
by: choyk1 | last post by:
Hi all, I cannot serialize CultureInfo property as below. It invokes InvalidOperationException. public class One { private CultureInfo culture;
1
by: tommys | last post by:
Hi, I thought that using CultureInfo.CurrentUICulture would give me the current date format as set in the OS - but it did not work that way :-( When re-reading the docs I can see why: "Gets the...
0
by: Maileen | last post by:
Hi, I wrote in VB a small application which save old culture info before to change them for running Excel macro. It looks like that : Dim oldCI As System.Globalization.CultureInfo = _...
1
by: rerdavies | last post by:
OS: WIndows Server 2003. Currently logged in user is running with German(German) regional settings. Code fragment: System.Globalization.CultureInfo culture = new...
8
by: G.Ashok | last post by:
Hi, I have created CultureInfo object and specified required digit grouping in it. The one of the overloaded ToString methods of Decimal type has parameters to format the value with required...
4
by: Dirk Behnke | last post by:
How can I start a new process with a different CultureInfo? I have tried already to set the CultureInfo of the thread starting the new process before creating the Process object, but it doesn't...
8
by: Phil Jollans | last post by:
Hi, I am having difficulty overriding the ToString() method of CultureInfo using Visual Studio 2005. Exactly the same code works fine with Visual Studio .NET 2003. What I am doing is adding...
8
by: =?Utf-8?B?T2xpdmllciBHSUw=?= | last post by:
Hello, I try to convert a volume stored as a string value in an XML file into a Decimal object. The volume is stored with comma as decimal separator ("210,12") according to french habits. To be...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.