Windows Forms Application Speed ​​Optimization

How to speed up the optimization of Windows Forms applications?

I'm not talking about explicit .NET optimization methods - for example, NGEN -ing, object caching, etc. I have already tried this and that I want to reduce the form initialization time from 1500 ms to 500 ms.

Profiling determined the slowest code, and almost all of it in the InitializeComponent , and in this method the slowest lines

  • creating a (only new) WebBrowser component
  • resource loading icon (disgusting 500 ms)
  • creating ContextStripMenu
  • several calls to this.Controls.Add() also contribute.

At the moment, I can only see how to fix point (2) - move the icon data from the storage as a built-in resource to a personal field (for example, Base64 encoded string).

What to do with points 1, 3 and 4?

+3
source share
6 answers

The only thing I can think about what you can do is rewrite the controls you want to use and optimize them for initialization faster (as well as the Form class to optimize adding controls to the form).

I cannot understand how possible this is, and I think that you are going to be stuck with this, depending on your dependence on these controls.

+1
source

Upload the icon to a separate InitializeComponentAsync thread.

+1
source

Can you do lazy loading for your webbrowser control? If the tab is not the main view, you can load the web browser when this tab is activated.

Or you can download the form and then download the web browser (this can help you show something first and then show everything just like on the website).

0
source
  • Just take another class like ClsAppearance.cs .

  • Initialize all controls, e.g.

     static Infragistics.Win.Appearance txtBoxMidAppr = null; 

    Instead of the name appiarance1 I take my name as txtBoxMidAppr . because of this, it can be used for the entire text field, only after initialization.

  • Make a function in which we can initialize the appearance and call it when loading MDI / Main only once.

     public static void LoadAll() { txtBoxMidAppr = new Infragistics.Win.Appearance(); } 
  • Make another function here and grab the lookup code from the development window

     public static Infragistics.Win.Appearance App_txtBoxMidAppr //text_box_small { get { txtBoxMidAppr.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(93)))), ((int)(((byte)(93)))), ((int)(((byte)(93))))); txtBoxMidAppr.ImageBackground = global::CS_POS.Properties.Resources.text_box_small; txtBoxMidAppr.ImageBackgroundStyle = Infragistics.Win.ImageBackgroundStyle.Stretched; txtBoxMidAppr.ImageHAlign = Infragistics.Win.HAlign.Right; return txtBoxMidAppr; } } 
  • In the form design code, comment on all the settings for the appearance of the text field and place the function name to get the view from the ClsAppearance.cs class

     //appearance4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(93)))), ((int)(((byte)(93)))), ((int)(((byte)(93))))); //appearance4.ImageBackground = global::CS_POS.Properties.Resources.text_box_small; //appearance4.ImageBackgroundStyle = Infragistics.Win.ImageBackgroundStyle.Stretched; //appearance4.ImageHAlign = Infragistics.Win.HAlign.Right; this.uteNABoth.Appearance = CS_POS.App_Appearance.ClsAppearance.App_txtBoxMidAppr; 

    take all the controls and create a function in the class and call it from there.

So, the initialization of the appearance will go only once and can use a lot of time.

0
source

I changed the form loading strategy, this will significantly change the form loading time, now it takes on average 37 ms instead of 466 ms.

Method: For the first time Click on the “Top tab / icon”, the application will load the entire form under this tab / icon, and when you click on the form icon it will switch the visibility. Again, a visit to the Top-tab will not load the form under this tab.

0
source

One of the methods that I used in the past was multithreaded data loading, so that it runs simultaneously when the form is created. In this case, the data was downloaded from AD, it was reduced by about 1/3 of the download time.

0
source

Source: https://habr.com/ru/post/897774/


All Articles