7
votes

I am showing a splash form by starting a new thread immediately before running my main form.

In the method that is run by this thread, I am using Application.Run as shown in Option 1 below. Is this a correct way of doing this, or are there problems waiting for me becaue I have called Application.Run twice? An alternative is Option 2, also shown below where I call .ShowDialog() to display the form.

The splash form itself closes after a specified time, controlled within the form itself, and both options appear to work well.

So my question is: Which is preferred - Option 1 or Option 2? If you could give specific reasons for one or the other that would be great.

Thanks.

Snippet of Main:

// Run splash screen thread.
Thread splash = new Thread(new ThreadStart(ShowSplash));
splash.Start();

// Run main application.
Application.Run(new MainForm());

Show splash form option 1:

    static void ShowSplash()
    {
        Application.Run(new SplashForm());
    }

Show splash form option 2:

    static void ShowSplash()
    {
        using (SplashForm splash = new SplashForm())
        {
            splash.ShowDialog();
        }
    }
2
Download reflector and see how it was done for VB =).Ilya Khaprov
Am I the only one that hates splash screens? Just load the fricking application already and stop wasting my time.Winston Smith
@Trickster: I did exactly that and found that ultimately a call to Application.Run is used to display the splash form. Thanks for the idea! I've marked your answer as accepted.Andy
@Winston I partially agree, especially in the case where the application is of little relevance and shows a splash screen as a top-most window.Camilo Martin

2 Answers

3
votes

Option 2 will probably run into trouble because then you are using the same Mesageloop as the MainForm but from another thread.

Option 1 is fine.

1
votes

I realize that this may be an unusual viewpoint but have you considered not using a Splash screen and instead showing the information on the 'welcome page' or 'help > about' screen instead?

There are a handful of reasons to do this:

  1. Unless you get into multi-threading, a Splash Screen may not repaint properly if some alert/msgbox pops up over the top of it, negating the benefit of the splash screen entirely.

  2. Splash screens that show 'you have plugins x, y and z' installed can't really tell this until that information has been loaded up. By the time this info is loaded, your app is ready to go, so you'll either close the splash screen or it'll be in the way of the user.

  3. If I look away and miss the splash screen, I'll miss whatever information you're telling me. If 'License expires in 3 days' is part of that information, and today is Friday, that means I won't realise that on Monday, I can't use the app. Obscure, but I've seen it.