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 7683107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:43:14+00:00 2026-05-31T18:43:14+00:00

I need a thread-safe (concurrent) version of ObservableCollection in Silverlight 5. I’m struggling to

  • 0

I need a thread-safe (concurrent) version of ObservableCollection in Silverlight 5. I’m struggling to find a way to create one given the lack of multi-threading support in SL5 (no ReaderWriterLock, no Collections.Concurrent to speak of, etc).

I need the collection to support UI binding while being updated by another thread. It is not acceptable for my to dispatch all of my updates to the UI thread when the process runs in the background. Ideally, the background process is free to update the collection as needed and the UI receives notifications as changes occur. This is possible with .NET 4 and I’ve found ways to accomplish this for WPF but nothing for SL. I can’t use the WPF examples because they rely on ReaderWriterLock which, AFAIK, is not present in SL5.

Any direction and/or examples is appreciated.

UPDATE

Following the asynchronous communication pattern used (required) in Silverlight, the ‘callback’ method, or handler, runs on a different thread. Using the TPL (as we do), this is the task’s Continuation.

Because this code runs on a different thread, any statements that affect the ObservableCollection have to be marshalled back to the UI thread. This means that the process logic and time are now consuming the resources of the UI thread.

The point of the concurrent collections in .NET is to allow producers and consumers to run in different threads yet seamlessly work with the shared data in the collection. The ‘producers’ in a SL client application will be the async callback or task continuation with the ‘consumers’ being the UI which is bound to the collection.

  • 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-05-31T18:43:16+00:00Added an answer on May 31, 2026 at 6:43 pm

    I also ran into this problem repeatedly, which caused me to go down the same road you’re looking at. There is a library that has helped me immensely with this task:

    http://ch.codeplex.com/

    I’ve implemented my own ConcurrentObservableCollection using the TinyReaderWriterLock and implementing IList, INotifyCollectionChanged, INotifyPropertyChanged

    I used this blog post as a starting point.
    http://www.deanchalk.me.uk/post/Thread-Safe-Dispatcher-Safe-Observable-Collection-for-WPF.aspx

    In my version I allow all calls to execute on the calling thread and only marshal the INotifyCollectionChanged and INotifyPropertyChanged calls back to the UI Thread like this:

    public void Add(T item)
    {
        mSyncLock.LockForWriting();
        innerCollection.Add(item);
        mSyncLock.ReleaseForWriting();
    
        var index = IndexOf(item);
    
        OnNotifyPropertyChanged(COUNT_PROPERTY);
        OnNotifyPropertyChanged(INDEXER_PROPERTY);
        OnNotifyCollectionChanged(NotifyCollectionChangedAction.Add, item, index); // This is an overload of OnNotifyCollectionChanged(NotifyCollectionChangedEventArgs e)
    }
    

    where

    protected virtual void OnNotifyCollectionChanged(NotifyCollectionChangedEventArgs e)
    {
        if (CollectionChanged == null) return;
    
        ThreadSafeInvoke(() => CollectionChanged(this, e));
    }
    

    and

    private static void ThreadSafeInvoke(Action action)
    {
        if (Deployment.Current.Dispatcher.CheckAccess())
        {
            action.Invoke();
        }
        else
        {
            Deployment.Current.Dispatcher.BeginInvoke(action);
        }
    }
    

    This has worked well for me. There is a small performance hit involved with the locking, but it’s not significant for most uses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering what is the best way to make data thread-safe. Specifically, I need
I need to find a way to spin off a thread from a static
I need to make an ArrayList of ArrayLists thread safe. I also cannot have
I have a Queue object that I need to ensure is thread-safe. Would it
In my attempt to develope a thread-safe C++ weak pointer template class, I need
For being thread safe do we need to assign function parameters to the local
i need a thread safe map, i have something like this: (i'm very new
I need to put together a concurrent system with one shared Control.Concurrent.Chan between threads.
Is there a thread-safe way to concurrently consume the stdout from an external process,
I need a thread-safe Map with a time limited expiry policy. I tried looking

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.