public static void ShowElement(string elementName) { lock (mLockObject) { // In case it changes when the instruction is executed var currentElement = CurrentElement; if (!string.IsNullOrEmpty(elementName)) { string currentElementName = null; if (currentElement != null) { currentElementName = currentElement.Name; } mNextElement = elementName; if (currentElementName != elementName) { ElementToHighlight = null; } } else if (currentElement != null) { InstructionManager.AddSafe(() => { currentElement.Destroy(); CurrentElement = null; }); } } }
public void ShowElement(string name) { if (!string.IsNullOrEmpty(name)) { InstructionManager.AddSafe( () => GlueViewCommands.Self.ShowScreen(name)); } else { GlueViewCommands.Self.ClearShownElements(); } }
private void StartCreatingEnemiesForWave() { _currentlyGeneratingNewWave = true; void GenerateWaveIfNecessary() { var currentWave = CurrentWaveNumber < Waves.Count && !PlayerDataManager.PlayerHasBeatGame ? Waves[CurrentWaveNumber] : GenerateWave(); if (currentWave.EnemyCounts.TotalEnemies == 0) { var doh = 1; } Action stuffToDoOnPrimaryThread = () => FinishCreatingEnemiesForWave(currentWave); InstructionManager.AddSafe(stuffToDoOnPrimaryThread); } Task.Run((Action)GenerateWaveIfNecessary); }
public void StartAsyncLoad(string screenType, Action afterLoaded = null) { if (AsyncLoadingState == AsyncLoadingState.LoadingScreen) { #if DEBUG throw new InvalidOperationException("This Screen is already loading a Screen of type " + asyncScreenTypeToLoad + ". This is a DEBUG-only exception"); #endif } else if (AsyncLoadingState == AsyncLoadingState.Done) { #if DEBUG throw new InvalidOperationException("This Screen has already loaded a Screen of type " + asyncScreenTypeToLoad + ". This is a DEBUG-only exception"); #endif } else { AsyncLoadingState = AsyncLoadingState.LoadingScreen; asyncScreenTypeToLoad = ScreenManager.MainAssembly.GetType(screenType); if (asyncScreenTypeToLoad == null) { throw new Exception("Could not find the type " + screenType); } #if REQUIRES_PRIMARY_THREAD_LOADING // We're going to do the "async" loading on the primary thread // since we can't actually do it async. PerformAsyncLoad(); if (afterLoaded != null) { afterLoaded(); } #else mNumberOfThreadsBeforeAsync = FlatRedBallServices.GetNumberOfThreadsToUse(); FlatRedBallServices.SetNumberOfThreadsToUse(1); Action action; if (afterLoaded == null) { action = (Action)PerformAsyncLoad; } else { action = () => { PerformAsyncLoad(); // We're going to add this to the instruction manager so it executes on the main thread: InstructionManager.AddSafe(new DelegateInstruction(afterLoaded)); }; } #if WINDOWS_8 || UWP System.Threading.Tasks.Task.Run(action); #else ThreadStart threadStart = new ThreadStart(action); Thread thread = new Thread(threadStart); thread.Start(); #endif #endif } }