4

I've currently an issue with switching languages in MVC while using async

This works fine :

public ActionResult Index()
{
    Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("fr");
    Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("fr");
    return View("Index");
}

This code won't work (when using async, it will keep my default language nl, while it's set to fr):

public async Task<ActionResult> Index()
{
    Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("fr");
    Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("fr");
    return View("Index");
}

Any idea why my @Resource won't work when using async and how i could solve this? (for keeping a better overview, i didn't include my await stuff within the code)

Many thanks already!

Edit: I've found some solution, but i'm not sure if it could provide some issues when multiple users are looking on the same page? https://weblogs.asp.net/morteza/how-to-set-currentculture-for-all-threads-in-a-domain-in-net-4-5

Kind regards, Kurt

  • 1
    Possible duplicate of [Keep CurrentCulture in async/await](https://stackoverflow.com/questions/30662668/keep-currentculture-in-async-await) – IPValverde Apr 07 '19 at 07:33
  • I think you are facing some error during your await task. check if your task is being completed? – Elyas Esna Apr 07 '19 at 11:26
  • Hi Elyas, Thanks for your response. https://weblogs.asp.net/morteza/how-to-set-currentculture-for-all-threads-in-a-domain-in-net-4-5 I think it's more related to this, but i'm not sure on how trustworthy this solution is. Kind regards, Kurt – Kurt Colemonts Apr 08 '19 at 08:30

0 Answers0