What’s new in WPF 3.5 SP1: Splash Screen to improve perceived startup perf

Summary:

To improve the perception of a more responsive startup experience many WPF applications added a Splash Screen to their startup. The Splash Screen, which does not load WPF code shows as soon as possible and is displayed until the application main window is rendered.
Up until 3.5 Sp1 we pointed developers to sample code available on this blog.
In the just released .Net 3.5 SP1 we added basic Splash Screen support and new APIs and we recommend that you take advantage of it. (See download locations below)

A Visual Studio 2008 Sp1 Item Template that makes adding a Splash Screen much easier is available on WPF Futures site on www.codeplex.com/wpf.

How to Use:

     Approach A:

The easiest way to add is by using VS 2008 SP1.
·  Create a new Standalone VB or C# WPF project in VS 2008 Sp1. Verify “Target Framework” project property is “.Net Framework 3.5”

·   Add an image (your splash screen image) to the project (e.g. by drag and drop) 

·   Set the image BuildAction to SplashScreen

·   Do F5 ( Build+Run), splash screen should be shown.

·   To disable the Splash Screen image functionality you can either:

   o Remove the “SplashScreen.png” image from the project, or

   o Set the splash image BuildAction to ‘None’ .

image

Upon compile, the build (PresentationBuildTasks.dll) will generates below code in App.g.cs:

    1: SplashScreen splashScreen = new SplashScreen("Splashscreen1.png");
    2: splashScreen.Show(true);
    3: MyApp.App app = new MyApp.App();
    4: app.InitializeComponent();
    5: app.Run();

Note: Above code will be generated in VS 2008 Sp1 only if the “Target Framework” project property is “.Net Framework 3.5”. Otherwise no code will be generated.

Approach B:

Install the Splash Screen Visual Studio 2008 Sp1 Item Template from the WPF Futures site.

· Create a new Standalone VB or C# WPF project in VS 2008 Sp1. Verify “Target Framework” project property is “.Net Framework 3.5”

· In VS, Right-Click on your Project and then select “Add / New Item… / Splash Screen (WPF)”.

· Notice the new image BuildAction is set to SplashScreen for you.

· Do F5 (Build+Run), the default splash screen image that was installed with the template will be shown (you likely want to replace with your own Splash Screen image)

image

Approach C:

Another approach is to directly use the new public Splash Screen APIs. With this approach you can set the ‘BuildAction=Resource’.

For example you can call the following code:

    1: SplashScreen appSplash = new SplashScreen("Splashscreen1.png");
    2: appSplash.Show(false);
    3: //….do some work…
    4: appSplash.Close( TimeSpan.FromSeconds(0.3)); // Splash to fadeout in 300ms

The WPF Splash Screen APIs are defined as below:

    1: namespace System.Windows
    2: {
    3:     public class SplashScreen
    4:     {
    5:         public SplashScreen(string resourceName);
    6:         public SplashScreen(Assembly resourceAssembly, string resourceName);
    7:         public void Show(bool autoClose);
    8:         public void Close(TimeSpan fadeOutDuration);    
    9:     }
   10: }

public ApplicationSplashScreen(string resourceName)

Behavior

Constructor. resourceName points to the embedded splash image

Exceptions

none

public ApplicationSplashScreen(Assembly resourceAssembly, string resourceName)

Behavior

Constructor. resourceAssembly specify the assembly in which resources lives resourceName points to the embedded splash image

Exceptions

 none

public void Show(bool autoClose);

Behavior

Constructor. Shows the splash image.

If autoClose is true, the code uses the dispatcher to queue an item at Idle priority, enabling the Splash screen to start fading out using the default fadeOutDuration (300 msec) after the application first renders.

If autoClose is false, the app is responsible to call Close(fadeOutDuration), in this case the splash screen fades out using the provided fadeOutDuration.

Exceptions

 IOException if resource provided in constructor not found in app assembly

public void Close(TimeSpan fadeOutDuration)

Behavior

Closes the splash window.

fadeOutDuration is the time for splash screen to fade out. If autoClose is true, WPF will close the window and use a 300 msec as the default fadeOutDuration.

Exceptions

none

Caveats:

It is important to understand that the Splash Screen has the following limitations:

· It does not actually improve application cold startup time.

· Cannot display sequence of splash images or animation.

· Does not support for animated GIFs

· Does not support earlier versions of VS (earlier than VS2008 Sp1). You should still be able to use the APIs (e.g. Approach C)

· Does not support XBAPs (XBAPs already have their own improved coldstart progress page in .Net 3.5 Sp1)

· Does not have XAML support for setting splash screen image

· Expression Blend does not provide UI to set the SplashScreen build action

.Net 3.5 SP1 Download locations:

Content

Links

Visual Studio 2008 Express Editions with Service Pack 1 (Bootstrappers)

https://go.microsoft.com/fwlink/?LinkId=123679

Visual Studio 2008 Express Editions with Service Pack 1 (iso)

https://go.microsoft.com/fwlink/?LinkId=123680

Visual Studio 2008 Service Pack 1 (Bootstrapper)

https://go.microsoft.com/fwlink/?LinkId=122094

Visual Studio 2008 Service Pack 1 (iso)

https://go.microsoft.com/fwlink/?LinkId=122095

Visual Studio Team System 2008 Team Foundation Server Service Pack 1

https://go.microsoft.com/fwlink/?LinkId=124829

.NET Framework 3.5 Service Pack 1

https://go.microsoft.com/fwlink/?LinkId=124150