Aaron Deming
Aaron Deming

Reputation: 1045

Splash screen never fully loading before being closed

I am currently adding a splash screen to my winform. My splash screen is just another form, where,

this.Text = "";
this.ControlBox = False;

All that is in the form is a PictureBox with a BackgroundImage and

this.BackgroundImageLayout = BackgroundImageLayout.Center 

and a ProgressBar that increments the value until the initialization of my MainForm is complete.

I use Show rather than ShowDialog to open the Splash. Well, the ProgressBar works perfectly as it should, but the BackgroundImage in the PictureBox never seems to load. All I see is a white background with a ProgressBar.

I use SplashScreen.Show() in the same method that increments the ProgressBar, and this method is called in a method that is called from the constructor of the MainForm.

I have tried using SplashScreen.Show in a separate thread but that caused the same problem. Any help would be greatly appreciated, and I'm willing to provide any more information if needed.

Solved:

When starting it in its own thread ShowDialog must be used because Show will close the form when the thread ends, but with ShowDialog, the thread will stay running until the form is closed. Thanks for everyone's help.

Upvotes: 0

Views: 315

Answers (2)

Chris Shain
Chris Shain

Reputation: 51339

The problem is that your splash screen is being shown on the main thread, which immediately then goes on to do the other work of initializing your application and never has a chance to draw the splash screen.

You'll need to run your splash screen on its own thread to allow for it to draw cleanly. See http://msdn.microsoft.com/en-us/library/aa446493.aspx

Upvotes: 1

Eric J.
Eric J.

Reputation: 150108

My guess is that you are blocking the message queue, but without seeing more code I can't be sure.

You may want to have a look at this splash screen project. I have used it before. Works great.

http://www.codeproject.com/Articles/5454/A-Pretty-Good-Splash-Screen-in-C

Among other things, that project runs the splash screen on a separate thread to keep it responsive and prevent message queue blocking.

Upvotes: 3

Related Questions