How to quickly download a winforms application

I have a winforms application. the main form has many controls, and this is one of the reasons it loads very slowly. what I would like to do is speed up the form loading.

I installed startupdate and endupdate. The form does not appear in the background workflow because it is the main form. There are no initial forms. When the user clicks the application icon, this is the first form that loads. Adding a progress bar or any form of splash is not a good idea for me.

I checked here other stack overflow questions, but they don't seem to be facing the same issue as me.

If there are a few examples / ideas that you have in mind, it would be nice if you could share it with me.

Thank you and respectfully Gagan Janjua

+6
source share
4 answers

A few suggestions:

  • Try to minimize the complexity of your user interface. Your users will thank you and you will have fewer controls to download. For example, if you have 3 or 4 controls that are not used often, can you move them to a dialog box or a pending โ€œadvancedโ€ section of your form so that you can delay the creation / display of them? Are all controls necessary? Indeed? Think about the workflow you are trying to achieve - is this the current set of controls, the easiest way to achieve a workflow? Should you immediately display all the controls? Perhaps you could place them to separate tabs in a tab control (and thus only actually create the controls when the tab is shown)?

  • Can you reduce the range of control types used? Each new type of control can make your program load a new dll to support it. Each DLL that needs to be initialized causes additional startup time.

  • Are you using any controls that start slowly? A simple text box will be fast, but a complex graphic control may be slow.

  • How many assemblies (of yours) are loaded? Combine all the code in one assembly (for example, with ILMerge), and the load time will probably improve quite a bit.

  • Remove any initialization code that is not needed. Can you simplify the initialization? Is it possible to postpone the transfer of any initialization (for example, only create some member variables when the user clicks on the first button that really needs data to be present, do not try to create a database connection if it is not already needed, etc. .)

  • Can you defer the creation of (some) user interfaces? For example, you can place a group of controls in a separate UserControl form, and then add this form programmatically to your MainForm shortly after launch (for example, on a timer). This will allow your MainForm to appear very quickly, and then it will soon be filled with additional controls, which may not improve the actual launch time, but it will โ€œfeelโ€ much faster and respond more quickly to the launch. (This approach can also be extremely effective if MainForm scrolls and those additional controls are not displayed on the screen, because they need to be created only if the user scrolls enough to see them).

  • Are you showing any information that may be slow to load (for example, large raster images or data received from an SQL server)? Can you delay the download or run it as a background thread? Use compression to speed up loading? Decrease resolution to minimize the amount of data that needs to be downloaded? Pre-process the data and store it in the quick launch cache the next time the program starts?

  • Is it possible to replace some elements with an optimized approach? for example, you can create a โ€œbutton barโ€ as a set of 10 separate controls or as a single control that draws with the appearance of 10 buttons. It is much simpler to make a single control initialized and redraw faster than 10 separate controls.

And, of course, as soon as the most obvious low-hanging fruits were picked (or even earlier):

  • Run the program under the profiler and see where it spends its time.
+10
source

Try to minimize the code that runs during the on load main form or any control that fits into the main form.

You can also explore NGEN , which is a Microsoft tool that helps improve the performance of managed applications.

+2
source

When it loads the form, it initializes all its controls.
The form itself will not take you much time. These are your controls.

Go to your controls and see what can be improved on their constructors and initializers.

0
source

Do you need all the controls at once? If possible, you can download them programmatically after some events that let you know that you need this control.

0
source

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


All Articles