Click here to Skip to main content
13,002,275 members (74,262 online)
Click here to Skip to main content
Add your own
alternative version


10 bookmarked
Posted 14 Apr 2013

WPF Splash Screen With Minimum Duration

, 24 Apr 2013
Rate this:
Please Sign up or sign in to vote.
How to make a splash screen appear for a minimum duration with very little code


Splash screens are easy to add to WPF applications, but allow for little flexibility. In particular, you cannot specify a minimum duration that a splash screen can appear for. Such a minimum duration can be desirable to ensure users on faster and slower PCs have a similar loading experience. A minimum duration can also ensure that users on fast PCs do not simply see the screen flash as the splash appears and vanishes. This tip shows how to simply and cleanly show a SplashScreen for a minimum period of time, without resorting to sleeping threads or other hackish solutions.  

Using the Code

To specify a minimum showing duration, we inherit from the SplashScreen class and provide a new Show() method:

public class SplashScreen2 : SplashScreen
    private DispatcherTimer dt;
    public SplashScreen2(string resourceName)
        : base(resourceName)
    { }
    /// <summary>
    /// Shows the splash screen
    /// </summary>
    /// <param name="minDur">The minimum duration this splash should show for</param>
    /// <param name="topmost">True if the splash screen should appear 
    /// top most in windows. Recommended to be true, to ensure it does not appear 
    /// behind the loaded main window</param>
    public void Show(TimeSpan minDur, bool topmost = true)
        if (dt == null) //prevent calling twice
            base.Show(false, topmost);
            dt = new DispatcherTimer(minDur, DispatcherPriority.Loaded, 
                        CloseAfterDelay, Dispatcher.CurrentDispatcher);
    private void CloseAfterDelay(object sender, EventArgs e)

The Show method above shows the SplashScreen but states that it will manually close itself. It then starts a new DispatcherTimer, which will call CloseAfterDelay when both:

  1. The timespan has completed AND
  2. The application has loaded.

To use the new SplashScreen2:

  1. Add an image to your WPF project. Under properties for your image, change 'Build Action' to 'Resource'. Do not set it to SplashScreen, because this will insert unwanted code into your Main[] method.
  2. In App.cs, create and show a new SplashScreen2 in the constructor, specifying the minimum duration you wish it to show for:
public App()
    SplashScreen2 splash = new SplashScreen2("my_splash_image.jpg");
    splash.Show(TimeSpan.FromSeconds(2));//Show for at least 2 seconds min duration


  • April 14 2013: Project submitted.


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


About the Author

Lee Reid
Musink Limited
Australia Australia
Lee Reid is the creator of the music-composition software Musink. He is a PhD-candidate at the University of Queensland and CSIRO in the field of Neuroscience and Biomedical Imaging.

You may also be interested in...

Comments and Discussions

QuestionMissing code Pin
GenJerDan1-Apr-16 10:15
memberGenJerDan1-Apr-16 10:15 
AnswerRe: Missing code Pin
Lee Reid1-Jul-16 3:27
memberLee Reid1-Jul-16 3:27 
GeneralNice, simple example. Pin
polczym22-Nov-14 0:51
memberpolczym22-Nov-14 0:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 24 Apr 2013
Article Copyright 2013 by Lee Reid
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid