Wednesday, August 18, 2004

CultureInfo changed on Callback threads?

Basic scenario: -Winforms client calling an asp.net web service on Windows XP

Problem: When I perform an async web service call from a winform client, my Thread.CurrentCulture and Thread.CurrentUICulture are changed from the initiating thread's culture.

Some code:

Set all the Cultures to a different culture:

static void Main()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("fi-FI");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fi-FI");
Application.CurrentCulture = new CultureInfo("fi-FI");
Application.Run(new SomeForm());
}

Make an Async webservice call:

IAsyncResult ar = myWebService.BeginSomeWebServiceMethod(new AsyncCallback(MyCallback), "hi");

Recieve the callback:
private void GetDatabaseInfoCallback(IAsyncResult ar)
{
string retval = myWebService.EndSomeWebServiceMethod(ar);
//Thread.CurrentThread.CurrentCulture.Name is now "en-US"
}

Is this correct? How can I get my callback threads to be in the same culture as the Application thread?

No comments: