Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Current culture on backgroundworker #6501


User avatar
0
Ricavir created

Hi,

I'm facing an issue because of background worker culture (which is en-US by default). I would like to set it to tenant default language.

I already used CultureHelper class to convert a datetime value to the right format string.

But here, I need to set the whole thread of backgroundworker to the tenant culture.

I'm planning to use following code within DoWork method :

System.Threading.Thread.CurrentThread.CurrentCulture = ...

Is ABP framework providing an other way to do it ? Do I need to come back to the previous culture at the en of DoWork method process ?

Tks for you support


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can inject IAbpSession into your background worker class and use it's Use method. Something like;

    using (_session.Use(42, null)) { var tenantId = _session.TenantId; //42 var userId = _session.UserId; //null }

    For more information, see https://aspnetboilerplate.com/Pages/Documents/Abp-Session#user-identifier

  • User Avatar
    0
    Ricavir created

    Tks @ismcagdas.

    I've read the documentation but I'm not sure : do you mean that injecting AbpSession will automatically set the tenant/user default culture inside the using block ?

    Access to tenant/user settings can also be done in this way within a background worker ?

    BTW, I've used CultureHelper class (like it is ised on useremailer class) to format date strings within background workers.

  • User Avatar
    0
    ismcagdas created
    Support Team

    I've read the documentation but I'm not sure : do you mean that injecting AbpSession will automatically set the tenant/user default culture inside the using block ?

    @ricavir yes, exactly. Did you have a chance to try that ?