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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:14:28+00:00 2026-05-27T04:14:28+00:00

I have the following code: class Customers : BindableObject { private ObservableCollection<string> _Products =

  • 0

I have the following code:

class Customers : BindableObject
{

    private ObservableCollection<string> _Products = new ObservableCollection<string>();

    public ObservableCollection<string> Products
    {
        get
        {
            return _Products;
        }
        set
        {
            _Products = value;
            RaisePropertyChanged("Products");
        }
    }

    private string _Name = "John";

    public string Name
    {
        get
        {
            return _Name;
        }
        set
        {
            _Name = value;
            RaisePropertyChanged("Name");
        }
    }


    public Customers()
    {
        Products.Add("George");
        Products.Add("Henry");
    }

    public void LongRunningFunction()
    {
        Name = "Boo";

        Thread.Sleep(5000);

        Name = "Peter";

    }

    public void ThreadedLongRunningFunction()
    {
        Task t = new Task(new Action(LongRunningFunction));
        t.Start();

    }


    public void LongRunningFunctionList()
    {
        Products.Add("Boo");

        Thread.Sleep(5000);

        Products.Add("Booya");

    }

    public void ThreadedLongRunningFunctionList()
    {
        Task t = new Task(new Action(LongRunningFunctionList));
        t.Start();

    }

}

BindableObject implements INotifyPropertyChanged.

I then have in my MainWindow.xaml.cs

public partial class MainWindow : Window
{

    Model.Customers c = new Model.Customers();

    public MainWindow()
    {
        InitializeComponent();

        gridToBindTo.DataContext = c;
    }

    private void cmdRun_Click(object sender, RoutedEventArgs e)
    {
        c.LongRunningFunction();
    }

    private void cmdRunAsync_Click(object sender, RoutedEventArgs e)
    {
        c.ThreadedLongRunningFunction();
    }

    private void cmdRunListSync_Click(object sender, RoutedEventArgs e)
    {
        c.LongRunningFunctionList();
    }

    private void cmdRunListAsync_Click(object sender, RoutedEventArgs e)
    {
        c.ThreadedLongRunningFunctionList();
    }

}

My MainWindow has a label bound to Name, and a list box bound to Products.

In the threaded version of both of the functions, I don’t understand why I am allowed to operate on a property ‘Name’ (string) that is bound to the UI in another thread, but I’m not allowed to do the same for a ObservableCollection.

Can someone explain why there is a difference here ?

Regards

  • 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-27T04:14:29+00:00Added an answer on May 27, 2026 at 4:14 am

    ObservableCollection is not thread safe that’s why it can’t be modified across different Dispatchers. But you can always override the ObservableCollection to make it thread safe. Look at the sample here – http://tomlev2.wordpress.com/2009/04/17/wpf-binding-to-an-asynchronous-collection/

    Bottom line is to raise the collectionChanged and propertyChanged on the UI dipatcher where collection was created.

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

Sidebar

Related Questions

I have following code public class TEST { public static void main(String arg[]){ try
I have the following code: class Program { static void Main(string[] args) { new
I have following code class User attr_accessor :name end u = User.new u.name =
I have following code snippet: class ABC{ public: int a; void print(){cout<<hello<<endl;} }; int
I have the following code: class Foo<T> where T : struct { private T
Suppose I have the following code: class some_class{}; some_class some_function() { return some_class(); }
I have code as following: Public Class xxxSvcHostFactory Inherits ServiceHostFactory Protected Overrides Function CreateServiceHost(ByVal
I have following code snippet in c# public class Customer { public Customer() {
I have the following code: class IncidentTag: def __init__(self,tag): self.tag = tag def equals(self,obj):
I have the following code: class TimeOutException {}; template <typename T> class MultiThreadedBuffer {

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.