advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   TIP BANK
Browse DevX
Partners & Affiliates
advertisement
advertisement
advertisement
advertisement
 

Managing Your WPF Splash Screen's Lifecycle

Splash screens are a prerequisite for a professional-looking application. Learn how to manage their lifecycles in order to avoid throwing errors.  


advertisement
splash screen is created upon application startup and is ended after the the main Window class's initialization code executes. Professional-looking applications geenrally use splash screens to let their users know where the application is in the initiliazation process. This generic splash screen is different from the SplashScreen class provided by Microsoft (.NET Framework 3.5 SP1), which displays only an image file and only in the center of the screen.

Sometimes, adding splash screens can be problematic. For instance, suppose you've added a WPF window to your project and spiced it up with some animation effects, which you implemented directly in XAML. Then, you specified the Startup event handler in the app.xaml file, like this:


<Application x:Class="MyNamespace.App" Startup="Application_Startup">
In the App class, you added a property:

private static Thread threadSpashScreen;
public static Thread ThreadSpashScreen()
{
get { return app.threadSpashScreen };
}
You also added code for two methods as follows:

private void Application_Startup(object sender, StartuoEventArgs e)
{
threadSpashScreen = new Thread(ExecuteSplashScreen);
threadSplashScreen.SetAppartmentState(AppartmentState.STA);
. . .
threadSplashScreen.Start();
}
private void ExecuteSplashScreen()
{
YourSplashScreen splScr = new YourSplashScreen();
. . .
splScr.ShowDialog(); //Modal dialog box
}
At the end of the main Window class’s initialization code, you've called Abort():

App.ThreadSplashScreen.Abort();
This works without any visible problems. Or so you think.

It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com.
Already a member?



advertisement