views:

33

answers:

1

So, the problem is such as this: I have a method that does stuff and updates a progress bar. If I call the method after the form is fully loaded (i.e.: by assigning it to a button on the form) everything works fine. The problem is that I need the method to start working as soon as the form loads, by itself, so I would place it in the Form_Load method. The problem is that even though I call Application.DoEvents() right before calling that method from within Form_Load, the form doesn't show up until the method has completed everything.

As I said, if I let the form load first and call the method from another UI element for instance, everything works fine.

Thanks in advance.

+2  A: 

Form_Load occurs before the form has been painted to the screen. If you have any code within Form_Load, then the form will not appear before all the form within that event has executed.

You should make use of the BackgroundWorker class. You can add your progress bar code to the BackgroundWorker events and then start the BackgroundWorker Asyncronously from within Form_Load.

GenericTypeTea