Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

question about localization and multi threading

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DAXU@HOTMAIL.COM - 04 Jul 2007 10:18 GMT
Hello,

Suppose I have a windows form running in culture A, then the form
creates a new thread (call a method foo for example) and makes it
using culture B.
When method foo is running in the new thread, it may try to change a
label in the form. So code is like:
foo()
{
          string message = resMan.GetString("strLabel");
           if (label2.InvokeRequired)
               label2.Invoke(new MethodInvoker(foo));
           else
               label2.Text = message;

}

The problem is that it will never show the label as culture B as foo
finally goes to the thread the windows form is running (culture A).
So what is the best way to handle it?

The real code was written without consideration of localizaton but now
requirement is added to support multi cultures.

Many Thanks
Jerry
Patrice - 04 Jul 2007 10:50 GMT
If you have interleaved calls to multiple cultures inside your application,
you could explicitely pass a parameter to address the needed culture :
http://msdn2.microsoft.com/en-us/library/system.resources.resourcemanager.getres
ourceset.aspx


You may want to explain what you are trying to do (an application generally
uses a single culture at a given time, here it looks like you want to access
different culture from one call to another ?)

> Hello,
>
[quoted text clipped - 22 lines]
> Many Thanks
> Jerry
DAXU@HOTMAIL.COM - 04 Jul 2007 11:24 GMT
I am doing a risk reduction project to gather risks. It is not saying
that the real code would use different cultures in different threads.
That is just a idea in my mind and I wants to see the possible
solution if we do need it in future.

Also, I get this from another post:
"The CultureInfo.CurrentUICulture property defaults to the current
user interface language of Windows. Regardless of which system locale
setting
you choose, the application will load English resources on English
Windows. "

Supose I deploy the code to a UK site, by default the CurrentUICulture
will still be en-US (tested by create a virtual machine and set every
thing to uk related). However, I may have different resources for UK
and US, to let my code pick up UK resource, I am using this:
[DllImport("kernel32.dll", SetLastError = true)]
       static extern short GetSystemDefaultLangID();
private int getSystemLcid()
       {
           short systemLcid = GetSystemDefaultLangID();
           return systemLcid;
        }

to get System Locale and use it to set current Cluture.

Is it the right way?

Cheers,
Jerry

> If you have interleaved calls to multiple cultures inside your application,
> you could explicitely pass a parameter to address the needed culture :http://msdn2.microsoft.com/en-us/library/system.resources.resourceman...
[quoted text clipped - 32 lines]
> > Many Thanks
> > Jerry
Patrice - 05 Jul 2007 10:59 GMT
You could also avoid this by using a multinlingual version of Windows. AFAIK
this is basically how most applications are working i.e. the user interface
lanugage is a particular settings, the date/time formats and other behaviors
are another specific settings.

Else you could also invent your own criteria (or even do this based on an
application specific user preference if you wish).

Not tried but check both the effect of your settings with Culture and
UICulture...
---
Patrice

I am doing a risk reduction project to gather risks. It is not saying
that the real code would use different cultures in different threads.
That is just a idea in my mind and I wants to see the possible
solution if we do need it in future.

Also, I get this from another post:
"The CultureInfo.CurrentUICulture property defaults to the current
user interface language of Windows. Regardless of which system locale
setting
you choose, the application will load English resources on English
Windows. "

Supose I deploy the code to a UK site, by default the CurrentUICulture
will still be en-US (tested by create a virtual machine and set every
thing to uk related). However, I may have different resources for UK
and US, to let my code pick up UK resource, I am using this:
[DllImport("kernel32.dll", SetLastError = true)]
       static extern short GetSystemDefaultLangID();
private int getSystemLcid()
       {
           short systemLcid = GetSystemDefaultLangID();
           return systemLcid;
        }

to get System Locale and use it to set current Cluture.

Is it the right way?

Cheers,
Jerry

On 4 Jul, 10:50, "Patrice" <http://www.chez.com/scribe/> wrote:
> If you have interleaved calls to multiple cultures inside your
> application,
[quoted text clipped - 36 lines]
> > Many Thanks
> > Jerry
Mihai N. - 05 Jul 2007 11:07 GMT
> "The CultureInfo.CurrentUICulture property defaults to the current
> user interface language of Windows. Regardless of which system locale
[quoted text clipped - 6 lines]
> thing to uk related). However, I may have different resources for UK
> and US, to let my code pick up UK resource, I am using this:

Just set your CurrentUICulture to what you want.

Signature

Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email

Peter Duniho - 04 Jul 2007 17:48 GMT
> [...]
> The problem is that it will never show the label as culture B as foo
> finally goes to the thread the windows form is running (culture A).
> So what is the best way to handle it?

You're running into the problem because you use the same method to set the  
text as to translate it.  Don't do that.

Instead, make sure that the only thing you do in the invoked method is  
that which is really required: to set the control's Text property.  Get  
the string to set it to in a different method that calls the  
cross-thread-safe method, so that you are getting the string on the  
expected thread.

Pete

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.