Reputation: 16616
I have got a problem. I have windows forms application with dynamic generated layout, but i have a problem in performance. In this form i use DataBinding
from .NET 4.0
and databinding after setup works fine, but he binding setup time for ONE control blocking my application on approx 0.7 second. I have some controls and time of binging setuping is around 2 minutes.
I trying all possible solutions, I dont have any ideas without write self binding class. Why is wrong with my code?
case "Boolean":
{
Binding b = new Binding("Checked", __bindingsource, __ep.Name);
CheckBox cb = new CheckBox();
/*
* HERE is the start of problem
*/
cb.DataBindings.Add(b);
/*
* HERE is the end of problem
*/
__flp.Controls.Add(cb);
__bindingcontrol.AddBinding(b);
break;
}
Without problem code lines all works fast and without binding ;-( but i want binding turn on in normal speed.
PS1. I have suspended layout in generation time.
PS2. I have same problem with binding TextBox'es, PictureBoxe's, CheckBox is only example.
How to do that or more littley how to debug the problem, the vs2010 profiler says only the problem is the Binding and i know that.
EDIT: DataContext is from database. (Entity Framework)
Upvotes: 2
Views: 7109
Reputation: 16616
This working not fast because __bindingsource
have many elements. Binding
not working good with big collections and this is a problem.
__bindingsource
is a BindingSource
class. And must have much less elements to fast working. I solved this problem with creating another new BindingSource
instance for each BindingSet (I mean Binding onetime much elements to properties of one object) with only one element, only this what i want to use.
Upvotes: 2
Reputation: 9365
I had this problem, too. I set the DataSourceUpdateMode
to Never
(in the Binding
-class Constructor): The performance was then much much better. If you do not need to update your data source, this is the right way to go.
This performance issue happens due to the Validation-event that is fired. Even if a control loses the focus or is clicked, this fires a validation event, which can decrease drastically the performance of your application.
EDIT: Although I didn't bind to the EntityFramework, the performance was very bad. Setting the DataSourceUpdateMode
to Never
reduces the number of events fired. Once you set the DataSourceUpdatedMode
to Never
, the updates will be uni-directional: From DataSource to Control.
Upvotes: 0
Reputation: 65391
Not sure if this is the problem in your case, but binding can appear to take a long time if it triggers an "event storm". That is you bind to control A, which triggers a change in control B, which triggers a change in control A ....
One thing to check is then the events on the controls you are updating.
The other thing is, from your comments, it looks like you are sharing the __bindingsource between forms. This could be the root of the problem. Why are you doing this? Using a binding source per form would make your program more managable.
Upvotes: 2