Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
958 views
in Technique[技术] by (71.8m points)

winforms - Slow Databinding setup time in C# .NET 4.0

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.

  1. System.Windows.Forms.Control.ControlCollection.Add(class System.Windows.Forms.Control)
  2. System.Windows.Forms.ControlBindingsCollection.Add(class System.Windows.Forms.Binding)

EDIT: DataContext is from database. (Entity Framework)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...