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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:06:30+00:00 2026-05-19T16:06:30+00:00

I have a base class implementing INotifyPropertyChanged : protected void OnNotifyChanged(string pName) { if

  • 0

I have a base class implementing INotifyPropertyChanged:

protected void OnNotifyChanged(string pName)
{
    if (PropertyChanged != null)
    {
        PropertyChanged(this, new PropertyChangedEventArgs(pName));
    }
}

public event PropertyChangedEventHandler PropertyChanged;

I have a derived class with a property Latitude like so:

private double latitude;

public double Latitude
{
    get { return latitude; }
    set { latitude = value; OnNotifyChanged("Latitude"); }
}

My derived class also has a method Fly that manipulates Latitude.

I also have a Form with a TextBox bound to Latitude of my derived class:

txtLat.DataBindings.Clear();    
txtLat.DataBindings.Add("Text", bindSrc, "Latitude");

A thread is used to kick off Fly like so:

Thread tFly = new Thread(f.Fly);
tFly.IsBackground = true;
tFly.Start();

When Latitude changes, an exception is thrown:

DataBinding cannot find a row in the list that is suitable for all bindings.

  • 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-19T16:06:30+00:00Added an answer on May 19, 2026 at 4:06 pm

    This seems to be an odd issue with thread affinity. Ultimately, the code is trying to do the update from a non-UI thread – I’m unclear why it isn’t just displaying the cross-thread exception, though – I wonder whether this is actually a catch-all exception handler. If I remove the BindingSource (and bind directly to the object, which is valid) you do get a cross-thread exception (which I expected).

    Personally, I would be inclined to handle this manually, i.e. subscribe to the event with a method that does an Invoke to the UI thread and updates the Text manually. However, I’m just checking if some previous cross-threaded binding code might help…


    Here’s an example using Invoke:

    using System;
    using System.ComponentModel;
    using System.Threading;
    using System.Windows.Forms;
    
    class FlightUav : INotifyPropertyChanged
    {
        protected void OnNotifyChanged(string pName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(pName));
        }
        public event PropertyChangedEventHandler PropertyChanged;
        private double _latitude;
        public double Latitude
        {
            get { return _latitude; }
            set { _latitude = value; OnNotifyChanged("Latitude"); }
        }
        public void Fly()
        {
            for (int i = 0; i < 100; i++)
            {
                Latitude++;
                Thread.Sleep(10);
            }
        }
        [STAThread]
        static void Main()
        {
            using (Form form = new Form())
            {
                FlightUav currentlyControlledFlightUav = new FlightUav();
    
                currentlyControlledFlightUav.PropertyChanged += delegate
                { // this should be in a *regular* method so that you can -= it when changing bindings...
                    form.Invoke((MethodInvoker)delegate
                    {
                        form.Text = currentlyControlledFlightUav.Latitude.ToString();
                    });
                };
    
    
                using (Button btn = new Button())
                {
                    btn.Text = "Fly";
                    btn.Click += delegate
                    {
                        Thread tFly = new Thread(currentlyControlledFlightUav.Fly);
                        tFly.IsBackground = true;
                        tFly.Start();
                    };
                    form.Controls.Add(btn);
                    Application.Run(form);
                }
            }
        }
    
    
    }
    

    Here’s an example using a (modified) version of some old threading code of mine:

    using System;
    using System.ComponentModel;
    using System.Threading;
    using System.Windows.Forms;
    
    class FlightUav : INotifyPropertyChanged
    {
        protected void OnNotifyChanged(string pName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(pName));
        }
        public event PropertyChangedEventHandler PropertyChanged;
        private double _latitude;
        public double Latitude
        {
            get { return _latitude; }
            set { _latitude = value; OnNotifyChanged("Latitude"); }
        }
        public void Fly()
        {
            for (int i = 0; i < 100; i++)
            {
                Latitude++;
                Thread.Sleep(10);
            }
        }
        [STAThread]
        static void Main()
        {
            using (Form form = new Form())
            {
                FlightUav currentlyControlledFlightUav = new FlightUav();
                BindingSource bindSrc = new BindingSource();
                var list = new ThreadedBindingList<FlightUav>();
                list.Add(currentlyControlledFlightUav);
                bindSrc.DataSource = list;
    
                form.DataBindings.Clear();
                form.DataBindings.Add("Text", list, "Latitude");
    
                using (Button btn = new Button())
                {
                    btn.Text = "Fly";
                    btn.Click += delegate
                    {
                        Thread tFly = new Thread(currentlyControlledFlightUav.Fly);
                        tFly.IsBackground = true;
                        tFly.Start();
                    };
                    form.Controls.Add(btn);
                    Application.Run(form);
                }
            }
        }
    
    
    }
    public class ThreadedBindingList<T> : BindingList<T>
    {
        private readonly SynchronizationContext ctx;
        public ThreadedBindingList()
        {
            ctx = SynchronizationContext.Current;
        }
        protected override void OnAddingNew(AddingNewEventArgs e)
        {
            SynchronizationContext ctx = SynchronizationContext.Current;
            if (ctx == null)
            {
                BaseAddingNew(e);
            }
            else
            {
                ctx.Send(delegate
                {
                    BaseAddingNew(e);
                }, null);
            }
        }
        void BaseAddingNew(AddingNewEventArgs e)
        {
            base.OnAddingNew(e);
        }
        protected override void OnListChanged(ListChangedEventArgs e)
        {
            if (ctx == null)
            {
                BaseListChanged(e);
            }
            else
            {
                ctx.Send(delegate
                {
                    BaseListChanged(e);
                }, null);
            }
        }
        void BaseListChanged(ListChangedEventArgs e)
        {
            base.OnListChanged(e);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interface with several events I have base class implementing the interface
If I have a base class: class Base { public: virtual void Test()=0; };
I have some interface, and a class implementing this interface, say: interface IMyInterface {
I have a base class object array into which I have typecasted many different
I have a base class with an optional virtual function class Base { virtual
I have a base class that represents a database test in TestNG, and I
I have a base class with a property which (the get method) I want
I have a base class that has a private static member: class Base {
I have a base class vehicle and some children classes like car, motorbike etc..
I have a base class in which I want to specify the methods a

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.