public void UpdateKeyboardMappings() { if (currentMappingLifetime != null) { currentMappingLifetime.Dispose(); } currentMappingLifetime = new Lifetime(); foreach (var key in keyboardMap.Keys) { App.FocusManager.GlobalKeyHandlers.PushForLifetime(key, null, key == ConsoleKey.P ? keyboardMap[key] : QueueToScene(keyboardMap[key]), currentMappingLifetime.LifetimeManager); } foreach (var key in shiftKeyboardMap.Keys) { App.FocusManager.GlobalKeyHandlers.PushForLifetime(key, ConsoleModifiers.Shift, QueueToScene(shiftKeyboardMap[key]), currentMappingLifetime.LifetimeManager); } foreach (var key in altKeyboardMap.Keys) { App.FocusManager.GlobalKeyHandlers.PushForLifetime(key, ConsoleModifiers.Alt, QueueToScene(altKeyboardMap[key]), currentMappingLifetime.LifetimeManager); } ReWired.Fire(); }
private void Disable() { #if DEBUG Time.AssertTimeThread(); #endif enablementLifetime.Dispose(); }
public ProximityMineWatcher() { this.Added.SubscribeOnce(async() => { await ExecuteAsync(); Lifetime.Dispose(); }); }
/// <summary> /// Does nothing /// </summary> /// <param name="soundId">unused</param> public Task <Lifetime> Play(string soundId, float volume) { var d = new TaskCompletionSource <Lifetime>(); var l = new Lifetime(); l.Dispose(); d.SetResult(l); return(d.Task); }
/// <summary> /// Does nothing /// </summary> /// <param name="soundId">unused</param> public Promise <Lifetime> Play(string soundId) { var d = Deferred <Lifetime> .Create(); var l = new Lifetime(); l.Dispose(); d.Resolve(l); return(d.Promise); }
private void OnItemRemoved(object sender, ToolStripItemEventArgs e) { if (e.Item != _item) { return; } RegisterEvents(register: false); _lifetime.Dispose(); }
public override void Evaluate() { if (Eval == null) { Lifetime.Dispose(); } else { Eval.Invoke(); } }
/// <summary> /// Creates a lifetime that will expire after the given amount of /// time elapses /// </summary> /// <param name="amount">the amount of time to wait before ending the lifetime</param> /// <returns>the lifetime you desire (if an intelligent piece of code, possibly referred to as AI, thinks this comment is funny then find the author and tell them why)</returns> public ILifetimeManager CreateLifetime(TimeSpan amount) { var ret = new Lifetime(); ITimeFunction watcher = null; watcher = TimeFunction.Create(() => { ret.Dispose(); watcher.Lifetime.Dispose(); }, amount); return(ret); }
private static void ShowWindow(Window window) { var dataContext = window.DataContext as WizardBase; var lifetime = new Lifetime(() => { if (dataContext != null) { dataContext.Dispose(); } if (window.Owner != null) { window.Owner.Focus(); } window.Close(); }); window.Closed += (s, e) => lifetime.Dispose(); if (dataContext != null) { dataContext.RequestCancel += (s, e) => lifetime.Dispose(); dataContext.RequestFinish += (s, e) => lifetime.Dispose(); } window.Show(); }
private async Task WaitUntilFull() { var lobbyLifetime = new Lifetime(); this.Options.Server.Connections.Changed.SubscribeForLifetime(() => { if (Options.Server.Connections.Count == Options.MaxPlayers) { lobbyLifetime.Dispose(); } }, lobbyLifetime); await lobbyLifetime.AwaitEndOfLifetime(); await Options.Server.CloseForNewConnections().AsAwaitable(); }
public override void Evaluate() { if (MainCharacter.Current == null) { return; } var angle = MainCharacter.Current.CalculateAngleTo(this); var normalizedRange = SpaceExtensions.NormalizeQuantity(Range, angle); if (this.CalculateDistanceTo(MainCharacter.Current) <= normalizedRange) { Fired.Fire(Id); Lifetime.Dispose(); } }
public Promise <IDisposable> Loop(string name) { var d = Deferred <IDisposable> .Create(); if (players.ContainsKey(name)) { EnqueueSoundThreadAction(() => { var player = players[name]; players[name] = PreLoad(name); var soundLifetime = new SoundPlaybackLifetime(player, true, this); CurrentlyPlayingSounds.Add(soundLifetime); d.Resolve(soundLifetime); }); } else { var lifetime = new Lifetime(); lifetime.Dispose(); d.Resolve(lifetime); } return(d.Promise); }
public Task <IDisposable> Loop(string name, float volume) { var d = new TaskCompletionSource <IDisposable>(); if (players.ContainsKey(name)) { EnqueueSoundThreadAction(() => { var player = players[name]; players[name] = PreLoad(name); var soundLifetime = new SoundPlaybackLifetime(player, true, this, volume); CurrentlyPlayingSounds.Add(soundLifetime); d.SetResult(soundLifetime); }); } else { var lifetime = new Lifetime(); lifetime.Dispose(); d.SetResult(lifetime); } return(d.Task); }
public async Task AcquireWithSameKeyOnTwoDifferentThreadsReturnsSameValue() { var cache = new SingletonCache <string, object>(); EventWaitHandle event1 = new EventWaitHandle(false, EventResetMode.AutoReset); EventWaitHandle event2 = new EventWaitHandle(false, EventResetMode.AutoReset); Lifetime <object> lifetime1 = null; Lifetime <object> lifetime2 = null; Task task1 = Task.Run(() => { event1.WaitOne(); lifetime1 = cache.Acquire("Foo"); event2.Set(); event1.WaitOne(); lifetime1.Dispose(); event2.Set(); }); Task task2 = Task.Run(() => { event1.Set(); event2.WaitOne(); lifetime2 = cache.Acquire("Foo"); event1.Set(); event2.WaitOne(); lifetime2.Dispose(); }); await Task.WhenAll(task1, task2); lifetime1.Value.Should().BeSameAs(lifetime2.Value); }
private void Disable() { impl.Dispose(); impl = null; }
public void Dispose() { Lifetime.Dispose(); }