/// <summary> /// Trigger an update of all info providers in 1st instance /// </summary> /// <returns></returns> private void UpdateInfoStore(long playerId, databaseCache currentCache, InfoCollection localInfoStore, List <InfoProviderBase> localInfoProviders) { //Update the shared cache tracker for the current cache cacheTracker.Update(playerId, currentCache); //Reset all update flags to false localInfoStore.ResetAllUpdateFlags(); foreach (var provider in localInfoProviders) { provider.TriggerUpdateInfo(playerId, currentCache, cacheTracker); } foreach (var provider in localInfoProviders) { provider.UpdateFinished(providersTimeOutMilliSeconds); } }
public void UpdateProviders() { //Before we start the update we need to make sure to reset all update flags infoStore.ResetAllUpdateFlags(); var allProviders = selectedTaskTree.allProviders; var numberPrerequisites = selectedTaskTree.numberPrerequisites; var dependents = selectedTaskTree.dependents; //Go through the providers and set their required number of prerequisites to that for this tree foreach (var provider in allProviders) { provider.Value.PrerequesitesLeft = numberPrerequisites[provider.Key]; } //Loop through all providers and add them to the providerTask dictionary foreach (var provider in allProviders) { object provObj = provider.Value as object; if (ConcurrencyMode.Concurrency == ConcurrencyMode.ConcurencyModel.MultiCore) { Task p = new Task(TaskMethod, provObj); if (!providerTasks.ContainsKey(provider.Key)) { providerTasks.Add(provider.Key, p); } else { providerTasks[provider.Key] = p; } } else { Action p = new Action(() => { TaskMethod(provObj); }); if (!providerActions.ContainsKey(provider.Key)) { providerActions.Add(provider.Key, p); } else { providerActions[provider.Key] = p; } } } //Start the providers which have no prerequisites foreach (var provider in allProviders) { if (ConcurrencyMode.Concurrency == ConcurrencyMode.ConcurencyModel.MultiCore) { if (numberPrerequisites[provider.Key] == 0) { providerTasks[provider.Key].Start(); } } else { if (numberPrerequisites[provider.Key] == 0) { providerActions[provider.Key](); } } } //Wait for ALL providers to finish //We may not have started them all here but they are started as other providers finish //Once ALL providers have finished this method can return if (ConcurrencyMode.Concurrency == ConcurrencyMode.ConcurencyModel.MultiCore) { Task.WaitAll(providerTasks.Values.ToArray()); } }