Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, My application is reading files from a server through http and it does this on the window_Initialized event. This makes it read the stuff from the remote server before the gui appear on the screen which takes like 7 seconds. So from that you start the program it takes around 7 seconds for the GUI to appear becouse of the http requests and stuff. Can I make it show the GUI first and then once the gui is loaded it does the http stuff?
Posted

1 solution

Yes - you just need to move the code.
One way to try is to move the coed into the Form.Shown event - that should be called once and once only, when Show or ShowDialog is called on the form. However, I haven't tried doing any long running task in there - it is possible that you still won't see anything because I am not sure if the initial Paint event has been honoured by that point - I suspect not, but would have to check.

If that doesn';t work, the better solution anyway would be to move it off the UI thread completely, and into a BackgroundWorker class instance. MSDN has details and an example, but it's pretty simple to do - the only complication is that you can't access UI controls directly from the background worker. But that would mean the UI never, ever gets "stuck" while waiting for your server, which is a much better approach.
 
Share this answer
 
Comments
maxbre 17-Aug-13 19:34pm    
Thanks! The backgroundworked solution worked fine :)
OriginalGriff 18-Aug-13 3:03am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900