public static void ReloadResources(IEnumerable<Resource> resources) { lock (_globalLock) { while (_cache.Any()) { var elem = _cache.First(); lock (elem.Value.StateLock) { elem.Value.Save(); _cache.Remove(elem.Key); } } var resourceNames = resources.Select(r => r.ResourceName); var nodeStates = LoadStates(resourceNames); var gcCollector = CacheCollectorFactory.GetInstance().GetResourceCacheCollector(resources); foreach (var resource in resources) { var controller = ControllerBuilder.Build(resource); var resourceCache = new ResourceCache(resource, controller, gcCollector); foreach (var node in resourceCache.NodeStateInfo) { var savedNodeState = nodeStates.FirstOrDefault(s => s.ResourceName == node.ResourceName && s.NodeName == node.NodeName); if (savedNodeState != null) node.ApplyState(savedNodeState); else node.State = NodeState.Busy; // to prevent node usage before actual state update, which is async } _cache[resource.ResourceName] = resourceCache; } /* //foreach (string name in resourceNames) PFX.Parallel.ForEach(resourceNames, (name) => { UpdateNodesState(name); }); */ } }