Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8557349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:33:17+00:00 2026-06-11T15:33:17+00:00

The c# app that I’m working on uses an ObservableDictionary. The performance on this

  • 0

The c# app that I’m working on uses an ObservableDictionary. The performance on this is not nearly fast enough to accommodate it’s functionality. The ObservableDictionary is very rapidly being interacted with (Removing, Adding, and Updating elements) and has to sort every single time a change is made. Is there an alternative I can use to ObservableDictionary that would focus on performance and still be able to sort rapidly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:33:18+00:00Added an answer on June 11, 2026 at 3:33 pm

    It’s very simple to write your own that does not cause a rebinding each time an add / update or delete is done. We wrote our own because of this very reason. Essentially what we do is to disable the notification that a change has been made until all objects in the collection have been processed, and then we generate the notification. It looks something like this. As you can see, we use MvvmLight as our MVVM framework library. This will improve performance tremendously.

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Collections.Specialized;
    using System.Linq;
    using FS.Mes.Client.Mvvm.MvvmTools.MvvmLight;
    
    namespace FS.Mes.Client.Mvvm.MvvmTools
    {
        /// <summary>
        /// Our implementation of ObservableCollection. This fixes one significant limitation in the .NET Framework implementation. When items
        /// are added or removed from an observable collection, the OnCollectionChanged event is fired for each item. Depending on how the collection
        /// is bound, this can cause significant performance issues. This implementation gets around this by suppressing the notification until all
        /// items are added or removed. This implementation is also thread safe. Operations against this collection are always done on the thread that
        /// owns the collection.
        /// </summary>
        /// <typeparam name="T">Collection type</typeparam>
        public class FsObservableCollection<T> : ObservableCollection<T>
        {
            #region [Constructor]
            /// <summary>
            /// Constructor
            /// </summary>
            public FsObservableCollection()
            {
                DispatcherHelper.Initialize();
            }
            #endregion
    
            #region [Public Properties]
            /// <summary>
            /// Gets or sets a property that determines if we are delaying notifications on updates.
            /// </summary>
            public bool DelayOnCollectionChangedNotification { get; set; }
            #endregion
    
            /// <summary>
            /// Add a range of IEnumerable items to the observable collection and optionally delay notification until the operation is complete.
            /// </summary>
            /// <param name="items"></param>
            /// <param name="delayCollectionChangedNotification">Value indicating whether delay notification will be turned on/off</param>
            public void AddRange(IEnumerable<T> items, bool delayCollectionChangedNotification = true)
            {
                if (items == null)
                    throw new ArgumentNullException("items");
    
                DoDispatchedAction(() =>
                {
                    DelayOnCollectionChangedNotification = delayCollectionChangedNotification;
    
                    // Do we have any items to add?
                    if (items.Any())
                    {
                        try
                        {
                            foreach (var item in items)
                                this.Add(item);
                        }
                        finally
                        {
                            // We're done. Turn delay notification off and call the OnCollectionChanged() method and tell it we had a 'dramatic' change
                            // in the collection.
                            DelayOnCollectionChangedNotification = false;
                            this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
                        }
                    }
                });
            }
    
            /// <summary>
            /// Clear the items in the ObservableCollection and optionally delay notification until the operation is complete.
            /// </summary>
            public void ClearItems(bool delayCollectionChangedNotification = true)
            {
                // Do we have anything to remove?
                if (!this.Any())
                    return;
    
                DoDispatchedAction(() =>
                {
                    try
                    {
                        DelayOnCollectionChangedNotification = delayCollectionChangedNotification;
    
                        this.Clear();
                    }
                    finally
                    {
                        // We're done. Turn delay notification off and call the OnCollectionChanged() method and tell it we had a 'dramatic' change
                        // in the collection.
                        DelayOnCollectionChangedNotification = false;
                        this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
                    }
                });
            }
    
            /// <summary>
            /// Override the virtual OnCollectionChanged() method on the ObservableCollection class.
            /// </summary>
            /// <param name="e">Event arguments</param>
            protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
            {
                DoDispatchedAction(() =>
                {
                    if (!DelayOnCollectionChangedNotification)
                        base.OnCollectionChanged(e);
                });
            }
    
            /// <summary>
            /// Makes sure 'action' is executed on the thread that owns the object. Otherwise, things will go boom.
            /// </summary>
            ///<param name="action">The action which should be executed</param>
            private static void DoDispatchedAction(Action action)
            {
                DispatcherHelper.CheckInvokeOnUI(action);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The App that I'm working on requires to parse a very big Json file
I have an app that uses several prefixes and, while not frequent, it's also
The app that i am working on uses UIWebViews to display vimeo videos. Instead
The app that I'm working on allows the user to pick an image from
The app that I'm currently working on is supposed to overlay a square image.
I have a web app that I'm building. It uses 3 different web services
I have an android app that appears to be working fine - but I
I have an Android app that uses a WebView to enable users to install
Scenario: An MVC3 app that uses constructor injection to provide services for a given
I'm coding an app that uses an existing database, that database has some tables

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.