public void OnlyDisposeOnce() { var counter = new DisposeCounter(); var disposables = new Disposables(); disposables.Add(counter); Assert.AreEqual(0, counter.DisposeCount); disposables.Dispose(); Assert.AreEqual(1, counter.DisposeCount); disposables.Dispose(); Assert.AreEqual(1, counter.DisposeCount); }
private void OnDestroy() { if (!Disposables.IsDisposed) { Disposables.Dispose(); } }
public override void OnFrameworkInitializationCompleted() { UnhandledExceptionLogging(); if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { appState = new AppState().DisposeWith(Disposables); Locator.CurrentMutable.RegisterConstant(appState); desktop.MainWindow = new MainWindow() { DataContext = new MainWindowViewModel().DisposeWith(Disposables) }; // write setting to file after main window dispose ConfigurationHelper.SaveAppSettingsOnDispose().DisposeWith(Disposables); Locator.CurrentMutable.RegisterConstant(desktop.MainWindow); desktop.ShutdownMode = Avalonia.Controls.ShutdownMode.OnMainWindowClose; Observable.FromEventPattern <ControlledApplicationLifetimeExitEventArgs> (h => desktop.Exit += h, h => desktop.Exit -= h) .Subscribe(_ => { Disposables.Dispose(); }) .DisposeWith(Disposables); } base.OnFrameworkInitializationCompleted(); }
public void NoAddAfterDispose() { var disposables = new Disposables(); disposables.Dispose(); Assert.Throws <ObjectDisposedException>(() => disposables.Add(Scope.Create(() => { }))); }
public override bool OnClose() { Disposables.Dispose(); Disposables = null; return(base.OnClose()); }
protected override void OnDetaching() { base.OnDetaching(); Disposables?.Dispose(); Disposables = null; }
protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { if (!Disposables.IsDisposed) { Disposables.Dispose(); } if (Bridge.Channel != null) { Bridge.Channel.Dispose(); } } if (eventSocket is OutboundSocket) { // todo: should we close the socket associated with the channel here? eventSocket.Dispose(); } eventSocket = null; disposed = true; } }
private unsafe void SignalWorkerThreadsToStop() { Observable.Interval(TimeSpan.FromMilliseconds(25)) .TakeWhile(_ => _runningThreads > 0) .Select(_ => { var result = new SwatcherAsyncResult { Buffer = new byte[0] }; var overlapped = new Overlapped { AsyncResult = result }; //the first parameter is null because we're not using IO completion callbacks; they're too slow. //we're taking the byte array from our empty byte array and passing that as user data to the overlapped. var overlappedPointer = overlapped.UnsafePack(null, result.Buffer); //when using IOCPs, we can send our own custom messages to the GetQueuedCompletionStatus //method by call PostQueuedCompletionStatus. In this case, we want to stop the threads that are //waiting on change events, so we will send a custom completion key "StopIocpThreads". WindowsFacade.PostQueuedCompletionStatus(CompletionPortHandle, 0, StopIocpThreads, overlappedPointer); return(Unit.Default); }) .AsCompletion() .Where(_ => Config.LoggingEnabled) .Subscribe(_ => { Disposables.Dispose(); Logger.Info("Swatcher has stopped"); }); }
protected virtual void Dispose(bool disposing) { if (disposed != null && !disposed.EnsureCalledOnce()) { if (disposing) { if (!Disposables.IsDisposed) { Disposables.Dispose(); } OtherLeg?.Dispose(); bridgedChannelsSubject.Dispose(); } if (eventSocket != null && eventSocket is OutboundSocket) { // todo: should we close the socket associated with the channel here? eventSocket.Dispose(); } eventSocket = null; Log.Debug(() => "Channel Disposed."); } base.Dispose(disposing); }
public override bool OnClose() { TabOpened = false; Disposables?.Dispose(); Disposables = null; return(base.OnClose()); }
public void UnsubscribeEvents() { lock (DisposablesLock) { Disposables?.Dispose(); Disposables = null; } }
public override bool OnClose() { CoinsList.OnClose(); Disposables?.Dispose(); Disposables = null; return(base.OnClose()); }
public void WhenADisposablesIsDisposedMultipleTimesItShouldDisposeChildrenDisposablesOnce() { // Given var calls = new List <string>(); var disposables = new Disposables() .Add( () => calls.Add("action1"), () => calls.Add("action2"), () => calls.Add("action3") ); // When disposables.Dispose(); disposables.Dispose(); disposables.Dispose(); // Then calls.Should().Equal("action1", "action2", "action3"); }
public void WhenADisposablesIsDisposedWithNoDisposablesItShouldNotFail() { // Given var disposables = new Disposables(); // When disposables.Dispose(); // Then // didn't failed }
public void Dispose() { if (Disposables.IsDisposed) { return; } m_tokenSource.Dispose(); Disposables.Dispose(); }
private volatile bool _disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { Disposables?.Dispose(); } _disposedValue = true; } }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { disposables.Dispose(); } disposedValue = true; } }
public void CtorEnumerable() { var test = ""; var disposables = new Disposables(new List <IDisposable> { Scope.Create(() => test += "a"), Scope.Create(() => test += "b"), Scope.Create(() => test += "c"), }); disposables.Dispose(); Assert.AreEqual("cba", test); }
public void ExplicitDispose() { TestDisposable o = new TestDisposable(); Assert.IsFalse(o.IsDisposed); var disposer = new Disposables(); disposer.Add(o); disposer.Dispose(); Assert.IsTrue(o.IsDisposed); }
public void WhenADisposablesIsDisposedItShouldDisposeChildDisposable() { // Given var calls = new List <string>(); var disposables = new Disposables() .Add(() => calls.Add("action1")); // When disposables.Dispose(); // Then calls.Should().Equal("action1"); }
public void CollectionInitialization() { var test = ""; var disposables = new Disposables { Scope.Create(() => test += "a"), Scope.Create(() => test += "b"), Scope.Create(() => test += "c"), }; disposables.Dispose(); Assert.AreEqual("cba", test); }
public void WhenADisposablesWithDisposableArrayIsDisposedItShouldDisposeChildrenDisposables() { // Given var calls = new List <string>(); var disposables = new Disposables() .Add( new Disposable(() => calls.Add("action1")), new Disposable(() => calls.Add("action2")), new Disposable(() => calls.Add("action3"))); // When disposables.Dispose(); // Then calls.Should().Equal("action1", "action2", "action3"); }
private volatile bool _disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { Disposables?.Dispose(); if (Global.ChaumianClient != null) { Global.ChaumianClient.StateUpdated -= ChaumianClient_StateUpdated; } } _disposedValue = true; } }
protected Workspace(ILog log, IDispatcherSchedulerProvider scheduler, IStandardDialog standardDialog) { _log = log; _scheduler = scheduler; _standardDialog = standardDialog; ClosingStrategy = new ClosingStrategy(log); ClosingStrategy.AddDisposable(Disposables); ClosingStrategy.Closing .TakeUntil(ClosingStrategy.Closed) .Subscribe(_ => { Closing(); CleanUp(); }); this.ExecuteOnClosed(() => Disposables.Dispose()); BusyViewModel = new BusyViewModel(scheduler); BusyViewModel.AddDisposable(Disposables); ActivationStateViewModel = new ActivationStateViewModel(log, scheduler); ActivationStateViewModel.AddDisposable(Disposables); ActivationStateViewModel.OnInitialise .SelectMany(_ => OnInitialise().ToObservable() .TakeUntil(BusyViewModel.BusyLatch)) .TakeUntil(ClosingStrategy.Closed) .Subscribe(_ => { }); ActivationStateViewModel.ActivationStateChanged .ObserveOn(scheduler.Dispatcher.RX) .Where(isActive => isActive) .TakeUntil(ClosingStrategy.Closed) .Subscribe(_ => OnActivate()); ActivationStateViewModel.ActivationStateChanged .ObserveOn(scheduler.Dispatcher.RX) .Where(isActive => !isActive) .TakeUntil(ClosingStrategy.Closed) .Subscribe(_ => OnDeActivate()); Show(); }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { var container = (IContainer)null; var workRegistry = new WorkManagerRegistry(); var notifier = new ServiceLogNotification(); var disposables = new Disposables(); var builder = new ContainerBuilder(); builder.RegisterModule(new ServiceModule(workRegistry, notifier, disposables, () => new DependencyFactory(container))); container = builder.Build(); using (var workManager = new WorkManager(workRegistry, new WorkManagerDependencyResolver(container), notifier)) { workManager.OnRuntimeState += (state) => { switch (state) { case ManagerRuntimeStates.Stopped: disposables.Dispose(); break; } }; if (!Environment.UserInteractive) { var servicesToRun = new ServiceBase[] { new WindowsService(workManager) }; ServiceBase.Run(servicesToRun); } else { workManager.Start(); Console.WriteLine($"WorkManager '{WorkManagerConfig.ApplicationName}' has started."); Console.WriteLine("Press any key to terminate..."); Console.ReadKey(); workManager.Stop(); } } }
protected override void OnAttached() { Disposables?.Dispose(); Disposables = new CompositeDisposable { AssociatedObject.GetObservable(InputElement.IsEnabledProperty).Subscribe(enabled => { if (enabled) { AssociatedObject.Opacity = OriginalOpacity.HasValue ? OriginalOpacity.Value : 1; } else { OriginalOpacity = AssociatedObject.Opacity; AssociatedObject.Opacity = 0.5; } }) }; }
public void Dispose() { if (wasDisposed || Kernel.applicationQuitting || this == null) { return; } wasDisposed = true; Disposables.Dispose(); DisposablesProperty.Dispose(); DisposablesProperty = null; OnDispose(); OnDisposing.Execute(); OnDisposing.Dispose(); OnDisposing = null; OnAfterBind.Dispose(); OnAfterBind = null; //If an error is thrown here, you are trying to dispose a model that was not bound. This should never happen/you should always bind your models and this comment is just here so you know whats wrong :) //_dManager.Remove(this); //If an error is thrown here, you are trying to dispose a model that was not bound. This should never happen/you should always bind your models and this comment is just here so you know whats wrong :) try { _dManager.Remove(this); } catch (Exception e) { if (!skipWarning) // sry, but I have some cases(in my NPC-Nodes) where I have a Model but unbound. I shouldn't have used MVC-Model in the first place.... { UnityEngine.Debug.LogError("Tried to dispose unbound MVC-Model:" + GetType().ToString()); UnityEngine.Debug.LogException(e); } } }
public void Dispose() { if (wasDisposed || Kernel.applicationQuitting || this == null) { return; } wasDisposed = true; Disposables.Dispose(); DisposablesProperty.Dispose(); DisposablesProperty = null; OnDispose(); OnDisposing.Execute(); OnDisposing.Dispose(); OnDisposing = null; OnAfterBind.Dispose(); OnAfterBind = null; _dManager.Remove(this); }
public void Dispose() { Disposables.Dispose(); }
public virtual void Dispose() { Debug.WriteLine("Disposing"); Disposables.Dispose(); }