1

My application uses Task objects to do some jobs. Each Task can have it's own language setting, so I use a separate CultureInfo instead of CultureInfo.CurrentCulture when formatting numbers and strings or load language specific resources. So far so good, but: Whenever I use framework functionality or sealed libraries who works with CultureInfo.CurrentCulture, of course, I get wrong results, because the CultureInfo.CurrentCulture is different from the Task scope CultureInfo.

I wish I could set the CultureInfo.CurrentCulture for the current Task scope. But my investigations says, that CultureInfo.CurrentCulture is per thread, and often my Tasks are running in the same thread.

So the question is: Is there a way to force CultureInfo.CurrentCulture to be specific for Task scope instead just for thread scope?

user1470240
  • 580
  • 3
  • 19
  • 2
    As far as I know: **No**, because of the restrictions you already mentioned. You might need to use Threads instead of Tasks. – Manfred Radlwimmer Mar 29 '18 at 06:56
  • 3
    Maybe this gives you more information: [Execute task with the CurrentCulture set to the Task creator CurrentCulture](https://stackoverflow.com/questions/25012508/execute-task-with-the-currentculture-set-to-the-task-creator-currentculture) – Manfred Radlwimmer Mar 29 '18 at 06:57
  • 1
    This got fixed in .NET 4.6, be sure to target that version. The MSDN article for CultureInfo.CurrentCulture has details. And of course if "it doesn't work" then you must show us. – Hans Passant Mar 29 '18 at 07:01

0 Answers0