// Simple helper to ease maintenance and improve readability.
private static void AddResourceSet(Dictionary <string, ResourceSet> localResourceSets, string cultureName, ref ResourceSet rs)
{
// InternalGetResourceSet is both recursive and reentrant -
// assembly load callbacks in particular are a way we can call
// back into the ResourceManager in unexpectedly on the same thread.
lock (localResourceSets)
{
// If another thread added this culture, return that.
ResourceSet?lostRace;
if (localResourceSets.TryGetValue(cultureName, out lostRace))
{
if (!object.ReferenceEquals(lostRace, rs))
{
// Note: In certain cases, we can be trying to add a ResourceSet for multiple
// cultures on one thread, while a second thread added another ResourceSet for one
// of those cultures. If there is a race condition we must make sure our ResourceSet
// isn't in our dictionary before closing it.
if (!localResourceSets.ContainsValue(rs))
{
rs.Dispose();
}
rs = lostRace;
}
}
else
{
localResourceSets.Add(cultureName, rs);
}
}
}