Thread problem with BindingList<T>

F

Frank VDL

Hi,

To be able to show my objects in a Grid, I've inherited my list
implementation from BindingList<T>.

The problem is that de objects in this list are created/changed/deleted
in different threads.
If I link the BindingList<T> implementation to a grid
(grdNodes.DataSource = Nodes.List), I get a thread exception when I try
to add a new object using a worker thread.

I know this is because the ListChanged event isn't synchronized, but
isn't this an error/bug in the bindinglist or DataGrid !
Shouldn't one of them synchronize the event ???


Kind regards
Frank Vanderlinden
 
J

Jon Skeet [C# MVP]

Frank said:
To be able to show my objects in a Grid, I've inherited my list
implementation from BindingList<T>.

The problem is that de objects in this list are created/changed/deleted
in different threads.
If I link the BindingList<T> implementation to a grid
(grdNodes.DataSource = Nodes.List), I get a thread exception when I try
to add a new object using a worker thread.

I know this is because the ListChanged event isn't synchronized, but
isn't this an error/bug in the bindinglist or DataGrid !
Shouldn't one of them synchronize the event ???

Do any of the classes involved claim to be thread-safe? If not, I don't
see that it's a bug.
You should be changing the data model *only* on the UI thread, if a UI
control is bound to it.

Jon
 
F

Frank VDL

"You should be changing the data model *only* on the UI thread, if a UI

control is bound to it. "

I agree, but I can't change how the datagridview handles the
ListChanged event.
Doesn't it has to sync it's ouwn events with the UI thread ?
 
J

Jon Skeet [C# MVP]

Frank said:
"You should be changing the data model *only* on the UI thread, if a UI
control is bound to it. "

I agree, but I can't change how the datagridview handles the
ListChanged event.
Doesn't it has to sync it's ouwn events with the UI thread ?

No. The point is that if you only change the list on the UI thread, all
will be well. That's your responsibility, not the control's.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top