none
Performance of ShowDialog method of Form class RRS feed

  • Question

  • There are 2 forms, let's call them as A and B. A has some controls and in Onload method will do something. B does not have any control just a blank form and does nothing in Onload method. 

    I use a tool to check performance for these 2 ShowDialog method of A and B. Of course A is much slower than B. Then I comment all code in Onload method of A, and check performance again. The performance of A just improves a little bit and still is much slower than B. So I do not know where is the place cost most time of method ShowDialog of A.

    Thanks a lot.


    CanadaProgrammer

    Monday, October 7, 2013 7:44 AM

Answers

  • You have mentioned that A has some controls on it. So, it will take some time to load and initialize all the controls. Go to designer.cs file of form A and you can see all initialization code the InitializeComponent method. That 'extra' time is spent executing this code.

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Monday, October 7, 2013 8:17 AM
  • You can speed up a form opening by moving code to the constructor instead of the load function.  where the initializecomponents is located.  You didn't specify if you are programming in Basic or in C#.  In basic if you put on the form "Sub New" you will see the intialize function.  the intialze component functon will consume the most time when a form is opened.  It only has to be called once for each form.  So when you have a form that you are opening more than once it make sense to move as much code as possible to the constructor so speed up the time it takes for a form to Load.  You can also use the ShowDialog() method to instead of the Load() method to speed up a form opening.

    jdweng

    Monday, October 7, 2013 8:03 AM

All replies

  • You can speed up a form opening by moving code to the constructor instead of the load function.  where the initializecomponents is located.  You didn't specify if you are programming in Basic or in C#.  In basic if you put on the form "Sub New" you will see the intialize function.  the intialze component functon will consume the most time when a form is opened.  It only has to be called once for each form.  So when you have a form that you are opening more than once it make sense to move as much code as possible to the constructor so speed up the time it takes for a form to Load.  You can also use the ShowDialog() method to instead of the Load() method to speed up a form opening.

    jdweng

    Monday, October 7, 2013 8:03 AM
  • You have mentioned that A has some controls on it. So, it will take some time to load and initialize all the controls. Go to designer.cs file of form A and you can see all initialization code the InitializeComponent method. That 'extra' time is spent executing this code.

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Monday, October 7, 2013 8:17 AM
  • You have mentioned that A has some controls on it. So, it will take some time to load and initialize all the controls. Go to designer.cs file of form A and you can see all initialization code the InitializeComponent method. That 'extra' time is spent executing this code.

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Thanks for reply.

    Yes, there are some controls but it can not cost so much time.


    CanadaProgrammer

    Monday, October 21, 2013 10:26 PM
  • I show you the performance:

    You see ShowDialog method consume most time and all other code(include my code) just consume a few time. 


    CanadaProgrammer

    Monday, October 21, 2013 10:32 PM
  • ShowDialog is only being called once and the first time a form object gets called all th econtrols have to be initialized which take time.  If you closed the form and reopened the same instance of the form the time would decrease significantly.

    jdweng

    Tuesday, October 22, 2013 9:24 AM