What is the best way to call a method right AFTER a form loads?

Posted by Jordan S on Stack Overflow See other posts from Stack Overflow or by Jordan S
Published on 2010-06-02T13:13:51Z Indexed on 2010/06/02 13:23 UTC
Read the original article Hit count: 297

Filed under:
|
|
|

I have a C# windows forms application. The way I currently have it set up, when Form1_Load() runs it checks for recovered unsaved data and if it finds some it prompts the user if they want to open that data. When the program runs it works alright but the message box is shown right away and the main program form (Form1) does not show until after the user clicks yes or no. I would like the Form1 to pop up first and then the message box prompt.

Now to get around this problem before I have created a timer in my Form, started the timer in the Form1_Load() method, and then performed the check and user prompt in the first Timer Tick Event. This technique solves the problem but is seems like there might be a better way.

Do you guys have any better ideas?

Edit: I think I have also used a background worker to do something similar. It just seems kinda goofy to go through all the trouble of invoking the method to back to the form thread and all that crap just to have it delayed a couple milliseconds!

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms