public IDisposable EnterMassUpdate() { _massUpdateScopeCount++; _waitingForMassUpdate = true; void DisposeAction() { _massUpdateScopeCount--; if (_massUpdateScopeCount == 0) { _waitingForMassUpdate = false; var args = GetChangeArguments(); if (args == null) { return; } OnCollectionChanged(args); OnPropertyChanged(nameof(Count)); _reset = false; _newItems = null; _oldItems = null; } } return(Disposable.FromAction(DisposeAction)); }
internal IDisposable BeginEventAddMoratorium() { if (!this.eventAddAllowed) { ExceptionUtil.ThrowInvalidOperationException("An event add moratorium is already in effect"); } this.eventAddAllowed = false; return(Disposable.FromAction(delegate { this.eventAddAllowed = true; }, false)); }
public static IDisposable Initialize(IUpdatesServiceHost host) { object sync = UpdatesService.sync; lock (sync) { if (instance != null) { ExceptionUtil.ThrowInvalidOperationException("Initialize has already been called"); } instance = new UpdatesService(host); return(Disposable.FromAction(delegate { Shutdown(); }, false)); } }
public void TestAutoSubscription() { var testHub = new MessagesHub(); var instance = new HandlerObject(); var subscriptions = MessagesUtils.AutoSubscribe(instance, testHub); using (Disposable.FromAction(() => { foreach (var s in subscriptions) { s.Subscription.Dispose(); } })) { string str1 = "value1"; string str2 = "value2"; int ival1 = 77; Assert.AreEqual(instance.StrValue, string.Empty); Assert.AreEqual(instance.IntValue, 0); NotificationMessage1.Broadcast(str1, testHub); Assert.AreEqual(instance.StrValue, str1); NotificationMessage2.Broadcast(str2, ival1, testHub); Assert.AreEqual(instance.StrValue, str2); Assert.AreEqual(instance.IntValue, ival1); } Assert.Throws <Exception>(() => { // all subscriptions must gone after using (...) block NotificationMessage1.Broadcast(string.Empty, testHub); }); }
internal IDisposable BeginEventAddMoratorium() { if (!this.eventAddAllowed) { ExceptionUtil.ThrowInvalidOperationException("An event add moratorium is already in effect"); } List <IDisposable> second = new List <IDisposable>(this.properties.Count); using (Dictionary <string, Property> .ValueCollection.Enumerator enumerator = this.properties.Values.GetEnumerator()) { while (enumerator.MoveNext()) { IDisposable item = enumerator.Current.BeginEventAddMoratorium(); second.Add(item); } } IDisposable tail = Disposable.FromAction(delegate { this.eventAddAllowed = true; }, false); this.eventAddAllowed = false; return(Disposable.Combine(Enumerable.Empty <IDisposable>().Concat <IDisposable>(tail).Concat <IDisposable>(second), false)); }
private IDisposable NotifyMassSelection() { _relay.Send <MassSelectionStartingMessage>(this); return(Disposable.FromAction(() => _relay.Send <MassSelectionFinishedMessage>(this))); }