New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CultureInfo in Dotnet Core #48077
Comments
Tagging subscribers to this area: @tarekgh, @safern, @krwq Issue DetailsHi, Example :
What are the CultureInfos for Option A and Option B at those moments ?
|
@kurtisane the current cultures is handled using the asynclocal. It is useful to review how asynclocal work in general. Current cultures (either CurrentCulture or CurrentUICulture) are stored as asynclocal. That means it will be stored in the async context of the executing thread. Every time you create a new child task, the current async context will be copied to this child task. changing the value in the child task wouldn't affect the parent task. In your example, Scope 1 is created and setting
Would use en-US.
It will copy the current culture value to the child tasks. i.e. the child tasks will have en-US. I know you are asking about .NET Core but here is some more info around this issue:
I hope this clarify the behavior and let's know if you have any more questions. |
First of all thank you very very much for your time and effort. The last think that is kind of not clear for me is the behavior of static classes, properties etc. : We have a Resource.Designer.cs. This contains a static CultureInfo and static ResourceManager. |
If you share some code, I can tell you the exact behavior. But in general, if the ResourceManager instance in Resource.Designer.cs is always using the static CultureInfo, then changing this static value will get applied regardless of the tasks. But if the ResourceManager is going to use CurrentUICulture, then you'll get the asynclocal behavior I described earlier. Feel free to send any more questions if there is anything unclear here. |
So we have this regular Designer.cs. Now when the Tasks are running in parallel and use the same Designer.cs and therefore the same static Properties are they going to effect each other. I'm not sure if it is even possible, but I'm not initializing any ErrorMessageResources Object. namespace MyDomain.Common.Logic.Resources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class ErrorMessageResources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal ErrorMessageResources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MyDomain.Common.Resources.ErrorMessageResources", typeof(ErrorMessageResources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Account has been inactivated.
/// </summary>
public static string Account_AccountInactivated {
get {
return ResourceManager.GetString("Account_AccountInactivated", resourceCulture);
}
}
}
} |
This call is using But, at any point if your code will set |
Thank you, so so much. I was struggeling with this so hard. Perfect explaination ! |
Hi,
I'm quite confused regarding CultureInfo, Parallesism, Scopes etc.
When a CultureInfo is set, it is set for a thread. For my understanding all Tasks that run in a Thread get the CultureInfo of the Thread they run in and when any of the Task changes the CultureInfo it is changing the CultureInfo of the whole Thread and therefore all of the Tasks. I have the assumption that scopes don't run in seperate threads and more in seperate tasks. Is that right ?
That would mean that if a scope changes the CultureInfo at any time it could effect parallel running scopes ?
Since the RequestCultureProviders also just change the CultureInfo of the current Thread could that effect across scopes ??? I'm really confused.
Example :
Option B : Scope No1 creates multiple Tasks
What are the CultureInfos for Option A and Option B at those moments ?
How does Dotnet Core handle this ?
How does Dotnet Core seperate scopes ?
The text was updated successfully, but these errors were encountered: