Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show a splash screen at once

We are dealing with slow start for WinForm applications (it is a large application and has many control assemblies). Control assemblies are DevComponents. Ngen was applied to prevent jit compilation, but the loading time just decreased a little.

The app has a splash screen, but it appears only in 12 seconds after the app has started. Is there any approach to show the splash screen at once?

Our current suggestion is to create a lightweight app with the splash screen, run the main app in a separate process, and close the lightweight app when initialization of the main app is done.

like image 460
Andrei Schneider Avatar asked Apr 21 '11 11:04

Andrei Schneider


1 Answers

You're never going to get a splash screen for a .NET application to show instantly. Even if you've NGen'ed the assemblies to eliminate the JIT-compile time, you still have to wait while all of the .NET Framework DLLs are loaded into memory. It's a pretty large framework, and it takes a non-trivial amount of time to load upon a cold start. Nothing you can really do about that.

Microsoft has tried to ease the pain as much as possible. The WindowsFormsApplicationBase class (it's defined in the Microsoft.VisualBasic namespace, but don't let that scare you off; it's perfectly usable from a C# application) provides a built-in mechanism for showing a splash screen. All you have to do is set its SplashScreen property to the appropriate form, and everything else is handled behind the scenes. It's been heavily optimized for maximum response time, even in a cold-start situation, but it's still not going to be instant.

The only other option that you have is to write small wrapper in unmanaged code, whose only purpose is to throw the splash screen up as quickly as possible, then call your .NET application to start launching itself. The lighter the better here, of course. C++ is an option, but C is probably a better option. You need to minimize the number of external libraries that you have to link, so a framework like MFC or Qt is definitely out: you need to target the Windows API directly.

The Visual Studio team did something similar in VS 2010. They have a pretty interesting explanation of the process available on their blog:

Even though Visual Studio 2010 uses WPF for its main window, using WPF for the splash screen would require that we wait for the CLR and WPF to initialize before we could paint a single pixel on the screen. While we’ve made some tremendous improvements in CLR and WPF startup speed in .Net 4.0, it still can’t quite match the performance of raw Win32. So, the choice was made to stay with native C++ code and Win32 for the splash screen.

But I wouldn't spend too much time here. Since you should generally give users the option to turn splash screens on and off, and most users will opt to turn it off, it's unlikely that very many people will ever see it in the first place. Any good optimization profiler would tell you that it isn't worth optimizing.

like image 90
Cody Gray Avatar answered Nov 14 '22 23:11

Cody Gray