3

I'd like to run a TPL Task under a given culture. I have an Action and a CultureInfo and want to run those in a Task. This is for unit testing purposes.

I could set Thread.CurrentCulture inside of the task but my concern is that the culture will "leak" and affect other thread pool work items that will non-deterministically reuse the current thread.

What's the proper way to do this?

boot4life
  • 4,966
  • 7
  • 25
  • 47
  • Are you doing this in an actual manually created thread, or because you are using C# async? – MindingData Feb 28 '16 at 23:24
  • I hope to avoid using manual threads. I hope to make use of tasks because they compose better. Basically, I want to run some work in parallel in a few tasks. The task code is culture sensitive and multiple cultures will be used. – boot4life Feb 29 '16 at 11:25
  • I think your best choice is this:http://stackoverflow.com/questions/25012508/execute-task-with-the-currentculture-set-to-the-task-creator-currentculture – George Vovos Mar 07 '16 at 23:18

0 Answers0