Example #1
0
        /// <summary>
        /// Disables all events until ResumeEvents is called. Implements reference counting to detect when to finally resume events, increasing performance by
        /// preventing un-necessary event handling.
        /// </summary>
        public void SuspendEvents()
        {
            // Lock changes
            lock (_syncRoot)
            {
                // Increment counter, do nothing when already suspended
                if (_suspendEventsCount++ > 0)
                {
                    return;
                }

                // Call method on all items
                foreach (var item in Items)
                {
                    item.SuspendEvents();
                }

                // Fire event
                EventsSuspended?.Invoke(this, EventArgs.Empty);
            }
        }
Example #2
0
 /// <summary>
 /// Called when events are suspended the first time, i.e. is not fired when nested.
 /// Fires the <see cref="EventsSuspended"/> event.
 /// </summary>
 protected virtual void OnEventsSuspended()
 {
     // Fire event
     EventsSuspended?.Invoke(this, EventArgs.Empty);
 }