I'm using HangFire 1.6 in an asp.net WebApi2 solution with Owin.
The server is setup for one culture (da-DK) - I cannot change this. My application must use another culture (en-US) to correctly parse text data it receives. Basically I just want everything in my solution to use this other culture and never use the culture on the server.
In my web.config I have:
<system.web>
<httpRuntime targetFramework="4.6.1" />
<globalization enableClientBasedCulture="false" culture="en-US" uiCulture="en-US"/>
</system.web>
and in my Startup
Configuration
method I have
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CurrentCulture;
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CurrentUICulture;
because there are async methods and I want all threads started to share the same culture as specified in web.config
I also have some recurring jobs running in HangFire
My problem is that whatever I do the recurring jobs just keep using the server culture (da-DK) as CurrentCulture (the CurrentUICulture seems to react to what I do:
I've searched the Hangfire docs and SO, but I have found nothing that could solve this for me. I would rather avoid having to hardcode a culture in the top of every method used in a recurring job
Hope someone can help me...
Follow-up (2017-11-21):
It turns out this has nothing to do with HangFire. Apparently CultureInfo.CurrentCulture
has not been set to the value provided in web.config when Startup.Configuration
is run, hence CultureInfo.DefaultThreadCurrentCulture
is set to a wrong value here. Once a controller executes the values are set to whatever is in the web.config.
For now I've decided to hard-code the culture in the Startup class to make sure it has been set on DefaultThreadCurrentCulture before any of the Hangfire recurring jobs execute