0
votes
public MainWindow()
    {
        Thread.Sleep(4000); 
        InitializeComponent();   
    }

In my main window, I put Thread.Sleep and set it for 4 seconds to create a 4 second delay before my application can run the rest of the code. In essence, I did this so that my Splash Screen is guaranteed to show for 4 seconds, rather than just how long the application spends loading (which is less than a second so far). I just attempted this while fooling around, so I'm just wondering if there are any drawbacks to this method.

I ask because there are a ton of questions out there asking people how to make their Splash Screens display longer. Is there a particular reason I shouldn't do this or why some other people haven't tried this?

1
Well, if I'm not mistaken, the thread that you're putting to sleep is the main thread. So, usually, this will be the same thread that the splash screen is running on, so it will be unresponsive and possibly will not even draw. Have you actually tried it?vesan
Tried it, works fine. I did it like this as opposed to hard coding anything: msdn.microsoft.com/en-us/library/cc656886%28v=vs.110%29.aspxJimmyK

1 Answers

5
votes

Some things to think about:

  • If you sleep the main GUI thread you may cause your splash screen to stop repainting if something moves over the top of it.
  • Windows may report your application as unresponsive if the main thread is busy in a thread sleep.
  • If you are doing any extra work, you don't want work-time + 4s.

A better way to do this would probably be to use a timer to close the splash screen instead.

However, slash screens are meant to appear when you're doing some work during initial load. If you don't have any work maybe showing a splash screen in the 1st place is the wrong idea?