Re: whats faster, initialize component, or form load?



Roger,

In this case, no, it is not going to make the program faster. You are
doing the same work, which is going to take the same amount of time, just in
a different order. The order of operations for your program is as follows
(generally):

Create form instance
Show form
Load event on form is called

All of this is synchronous. This is an important distinction.

If hypothetically, the whole process takes 10 seconds, and it takes 5
seconds to run the Load event on the form, then moving the code that takes
five seconds to the constructor is not going to make the code run any
faster. You are still going to take five seconds to perform that work, and
the overall time will not change.

I mentioned synchronous before becuase if you can do the work
asynchronously, then you could see a benefit in speed if you delegate the
work to another thread. However, you have to figure out whether or not the
work can be performed asynchronously.

--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"roger_27" <roger27@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3BE339FD-0096-475A-8C5E-FB8CA3D89CE9@xxxxxxxxxxxxxxxx
hey, I have some preliminary code in my program (check for a certain file,
define a like 15 variables) and I put it in the form load. I recently got
the idea to make a method for it, and do it in the constructor method
instead.

would this make the load time of the program faster? or is it the same as
leaving it in the form load.? any thoughts or ideas on this?

thanks.


.



Relevant Pages

  • Re: whats faster, initialize component, or form load?
    ... In this case, no, it is not going to make the program faster. ... Load event on form is called ... seconds to run the Load event on the form, then moving the code that takes ... the idea to make a method for it, and do it in the constructor method ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: datasource of child .ascx not visible to parent .ascx
    ... you dynamic load a usercontrol in your webpage. ... There is a datagrid in the usercontrol, and you databind the datagrid in ... But in parent's Load event, ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Need some info about the Load event of Forms and Usercontrols
    ... Does it get called for each ShowDialog? ... What's bothering me is that the second time, the load on the usercontrol is ... And the form load calls a usercontrol method. ... UC's Load event was run which reinitialized things. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: VB form_load and flow control
    ... but if I try 'Unload Me' or 'Form.Terminate' I ... check this condition BEFORE you load the form. ... You CAN unload a form in the Load event, ... the control returns after the form_load event. ...
    (microsoft.public.vb.general.discussion)
  • Re: Using SQL inside a Form
    ... If you're truly talking about the data being there at load, ... CASE NUMBER through code in the LOAD event (e.g., passed as open arguments, ... using it as the controlsource for a dropdown ...
    (microsoft.public.access.formscoding)

Loading