Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7190399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:30:21+00:00 2026-05-28T19:30:21+00:00

The active language is determined from the url and then set on the Thread.CurrentThread.CurrentUICulture

  • 0

The active language is determined from the url and then set on the

Thread.CurrentThread.CurrentUICulture = cultureInfo;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureInfo.Name);

That way the translations are retrieved from the correct resource files.

When using Async action on controllers, we have a background thread, where the Thread.CurrentThread.CurrentUICulture is set back to OS default. But also on the background thread we need the correct language.

I created a TaskFactory extension to pass the culture to the background thread and it looks like this:

public static Task StartNew(this TaskFactory taskFactory, Action action, CultureInfo cultureInfo)
{
    return taskFactory.StartNew(() =>
    {
         Thread.CurrentThread.CurrentUICulture = cultureInfo;
         Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureInfo.Name);

         action.Invoke();
     });
}

This allows me to do the following in an action controller:

 [HttpPost]
 public void SearchAsync(ViewModel viewModel)
 {
     AsyncManager.OutstandingOperations.Increment();
     AsyncManager.Parameters["task"] = Task.Factory.StartNew(() =>
     {
         try
         {
               //Do Stuff
               AsyncManager.Parameters["viewModel"] = viewModel;
         }
         catch (Exception e)
         {
             ModelState.AddModelError(string.Empty, ResxErrors.TechnicalErrorMessage);
         }
         finally
         {
             AsyncManager.OutstandingOperations.Decrement();
         }
     }, Thread.CurrentThread.CurrentUICulture);
 }



 public ActionResult SearchCompleted(Task task, ViewModel viewModel)
 {
     //Wait for the main parent task to complete. Mainly to catch all exceptions.
     try { task.Wait(); }
     catch (AggregateException ae) { throw ae.InnerException; }

     return View(viewModel);
 }

This all works perfectly, but I do have some concerns.

Is this the correct way to extend an action by setting the culture before invoking the original action ?

Does anyone know of a different way to pass te CurrentUICulture to a background thread for ASP.NET MVC Async actions ?

  • Session is not an option.
  • I do was thinking of using the CallContext.

Any other comments on this code ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:30:23+00:00Added an answer on May 28, 2026 at 7:30 pm

    It seems the described way in the question is the answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've 3 tables: Parts : Name : internal name, Active : bool Languages :
In Active Directory, there is a tab called Dial-In, and under that tab is
I want to query Active Directory from Windows PE 2.0, which is not supported
How can I query Active Directory from SQL Server 2005?
In MonoRail/Active Record if I want to grab all records that have a certain
The code I'm using below suppose to switch system active input / writing language
Which is the preferred development language for Windows 7 gadgets? I know that a
I'm searching for programming languages, libraries or frameworks that provide active expressions in the
What are the possible solutions for finding the current active language which appears on
Does anyone know in ASP.Net how to get the language of the currentculture without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.