我在 ASP MVC 网站上使用自动全球化。它工作正常,直到它到达一个并行块:
public ActionResult Index()
{
// Thread.CurrentThread.CurrentCulture is automatically set to "fr-FR"
// according to the requested "Accept-Language" header
Parallel.Foreach(ids, id => {
// Not every thread in this block has the correct culture.
// Some of them still have the default culture "en-GB"
}) ;
return View()
}
让并行块继承文化的最佳方法是什么?除了这个解决方案:
public ActionResult Index()
{
var currentCulture = Thread.CurrentThread.CurrentCulture ;
Parallel.Foreach(ids, id => {
// I don't know if it's threadsafe or not.
Thread.CurrentThread.CurrentCulture = currentCulture ;
}) ;
return View()
}