Beispiel #1
0
 protected void CheckReentrancy()
 {
     if (monitor.Busy && CollectionChanged != null && (CollectionChanged.GetInvocationList().Length) > 1)
     {
         throw new InvalidOperationException("ObservableCollectionReentrancyNotAllowed");
     }
 }
        private void OnCollectionChanged()
        {
            Count = _list.Count;

            while (_notifyQueue.TryDequeue(out var e))
            {
                var handlers = CollectionChanged?.GetInvocationList().OfType <NotifyCollectionChangedEventHandler>();
                if (handlers == null)
                {
                    return;
                }

                //var toDispatch = new List<NotifyCollectionChangedEventHandler>();
                //var lockDispatch = new object();

                var arg = e;

                //Parallel.ForEach(handlers, (handler) =>
                foreach (var handler in handlers)
                {
                    if (handler.Target is DispatcherObject dispatcherObject && !dispatcherObject.CheckAccess())
                    {
//                        lock (lockDispatch) toDispatch.Add(handler);
                        dispatcherObject.Dispatcher.Invoke(DispatcherPriority.DataBind, handler, this, arg);
                    }
 private void CheckReentrancy()
 {
     if ((monitor.Busy && (CollectionChanged != null)) && (CollectionChanged.GetInvocationList().Length > 1))
     {
         throw new InvalidOperationException("There are additional attempts to change this hash set during a CollectionChanged event.");
     }
 }
 private void notify(EventArgs e)
 {
     if (CollectionChanged != null && CollectionChanged.GetInvocationList().Any())
     {
         CollectionChanged(this, e);
     }
 }
 private void CheckReentrancy()
 {
     if (_monitor.Busy && CollectionChanged != null && CollectionChanged.GetInvocationList().Length > 1)
     {
         throw new InvalidOperationException("SynchronizedObservableCollection reentrancy not allowed");
     }
 }
Beispiel #6
0
 private void CheckReentrancy()
 {
     if (_monitor.IsBusy && CollectionChanged != null && CollectionChanged.GetInvocationList().Length > 1)
     {
         throw new InvalidOperationException(
                   "There was an attempt to change this collection during a CollectionChanged event");
     }
 }
Beispiel #7
0
 private void OnCollectionChanged(NotifyCollectionChangedEventArgs args)
 {
     if (CollectionChanged != null)
     {
         var N = CollectionChanged.GetInvocationList().Length;
         System.Diagnostics.Debug.WriteLine($"Number of items in event invocation list= {N}");
         CollectionChanged.Invoke(this, args);
     }
 }
 protected virtual void CheckReentrancy()
 {
     if (_monitor.Busy &&
         CollectionChanged != null &&
         CollectionChanged.GetInvocationList().Length > 1)
     {
         throw new InvalidOperationException(CoreStrings.ObservableCollectionReentrancy);
     }
 }
Beispiel #9
0
 protected void CheckReentrancy()
 {
     // ISSUE: reference to a compiler-generated field
     // ISSUE: reference to a compiler-generated field
     if (_monitor.Busy && CollectionChanged != null && CollectionChanged.GetInvocationList().Length > 1)
     {
         throw new InvalidOperationException("ObservableCollectionReentrancyNotAllowed");
     }
 }
Beispiel #10
0
 /// <summary>
 /// 再操作の確認
 /// </summary>
 protected void CheckReentrancy()
 {
     if (this.watcher.IsInScope)
     {
         if ((CollectionChanged != null) && (CollectionChanged.GetInvocationList().Length > 1))
         {
             throw new InvalidOperationException(string.Format(Properties.Resources.MESSAGE_EXCEPTION_INVALID_OPERATION_REENTRANCY_FORMAT, nameof(ResettableObservableCollection <T>), nameof(CollectionChanged)));
         }
     }
 }
 /// <summary> Check and assert for reentrant attempts to change this collection. </summary>
 /// <exception cref="InvalidOperationException"> raised when changing the collection
 /// while another collection change is still being notified to other listeners </exception>
 protected void CheckReentrancy()
 {
     if (_blockReentrancyCount > 0)
     {
         // we can allow changes if there's only one listener - the problem
         // only arises if reentrant changes make the original event args
         // invalid for later listeners.  This keeps existing code working
         // (e.g. Selector.SelectedItems).
         if (CollectionChanged?.GetInvocationList().Length > 1)
         {
             throw new InvalidOperationException(SR.ObservableCollectionReentrancyNotAllowed);
         }
     }
 }
Beispiel #12
0
 /// <summary> Check and assert for reentrant attempts to change this collection. </summary>
 /// <exception cref="InvalidOperationException"> raised when changing the collection
 /// while another collection change is still being notified to other listeners </exception>
 protected void CheckReentrancy()
 {
     if (_monitor.Busy)
     {
         // we can allow changes if there's only one listener - the problem
         // only arises if reentrant changes make the original event args
         // invalid for later listeners.  This keeps existing code working
         // (e.g. Selector.SelectedItems).
         if ((CollectionChanged != null) && (CollectionChanged.GetInvocationList().Length > 1))
         {
             throw new InvalidOperationException();
         }
     }
 }
Beispiel #13
0
 /// <summary> Check and assert for reentrant attempts to change this collection. </summary>
 /// <exception cref="InvalidOperationException">raised when changing the collection while another collection change is still being notified to other listeners</exception>
 private void CheckReentrancy()
 {
     if (_monitor.Busy)
     {
         // we can allow changes if there's only one listener - the problem
         // only arises if reentrant changes make the original event args
         // invalid for later listeners.  This keeps existing code working
         // (e.g. Selector.SelectedItems).
         if (CollectionChanged != null && CollectionChanged.GetInvocationList().Length > 1)
         {
             throw new InvalidOperationException($"{nameof(AsyncObservableKeyedSet<TKey, TItem>)} reentrancy not allowed.");
         }
     }
 }
    public void SomeMethod()
    {
        var handlers = CollectionChanged.GetInvocationList();

        foreach (NotifyCollectionChangedEventHandler handler in handlers)
        {
            CollectionChanged -= handler;
        }

        // do stuff here

        foreach (NotifyCollectionChangedEventHandler handler in handlers)
        {
            CollectionChanged += handler;
        }
    }
Beispiel #15
0
        protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            foreach (var handler in CollectionChanged.GetInvocationList().Cast <NotifyCollectionChangedEventHandler>())
            {
                var dispatcherObject = handler.Target as DispatcherObject;

                if (dispatcherObject != null && !dispatcherObject.CheckAccess())
                {
                    dispatcherObject.Dispatcher.BeginInvoke(DispatcherPriority.DataBind, handler, this, e);
                }
                else
                {
                    handler(this, e);
                }
            }
        }
 protected virtual void OnCollectionChangedMultiple(NotifyCollectionChangedEventArgs e)
 {
     if (CollectionChanged != null)
     {
         foreach (NotifyCollectionChangedEventHandler handler in CollectionChanged.GetInvocationList())
         {
             if (handler.Target is ICollectionView)
             {
                 ((ICollectionView)handler.Target).Refresh();
             }
             else
             {
                 handler(this, e);
             }
         }
     }
 }
Beispiel #17
0
        protected void CheckReentrancy()
        {
            if (_monitor.Busy)
            {
                Delegate[] delegates = null;
                if (_improve)
                {
                    if (ImprovedCollectionChanged != null)
                    {
                        delegates = ImprovedCollectionChanged.GetInvocationList();
                    }
                }
                else if (CollectionChanged != null)
                {
                    delegates = CollectionChanged.GetInvocationList();
                }

                if (delegates != null && delegates.Length > 1)
                {
                    throw new InvalidOperationException();
                }
            }
        }
        private void DoCollectionChanged(NotifyCollectionChangedAction action, params Fight[] fights)
        {
            Dispatcher dispatcher = null;

            foreach (var @delegate in CollectionChanged.GetInvocationList())
            {
                var dispatcherObject = @delegate.Target as DispatcherObject;
                if (dispatcherObject == null)
                {
                    continue;
                }
                dispatcher = dispatcherObject.Dispatcher;
                break;
            }
            if (dispatcher != null && dispatcher.CheckAccess() == false)
            {
                dispatcher.Invoke(DispatcherPriority.DataBind, (Action)(() => DoCollectionChanged(action, fights)));
            }
            else
            {
                CollectionChanged(this, new NotifyCollectionChangedEventArgs(action, fights));
            }
        }
Beispiel #19
0
        protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            using (BlockReentrancy())
            {
                if (e.NewItems != null)
                {
                    foreach (DynItem item in e.NewItems)
                    {
                        item.PropertyChanged += DynItem_PropertyChanged;
                    }
                }

                if (e.OldItems != null)
                {
                    foreach (DynItem item in e.OldItems)
                    {
                        item.PropertyChanged -= DynItem_PropertyChanged;
                    }
                }

                if (CollectionChanged != null)
                {
                    foreach (NotifyCollectionChangedEventHandler handler in CollectionChanged.GetInvocationList())
                    {
                        var dispatcherObject = handler.Target as DispatcherObject;
                        if (dispatcherObject != null && !dispatcherObject.CheckAccess())
                        {
                            dispatcherObject.Dispatcher.BeginInvoke(handler, DispatcherPriority.DataBind, this, e);
                        }
                        else
                        {
                            handler(this, e);
                        }
                    }
                }
            }
        }