JimmyK
JimmyK

Reputation: 5002

Thread.Sleep to make WPF Splash Screen show longer

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?

Upvotes: 0

Views: 355

Answers (1)

Ian
Ian

Reputation: 34519

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?

Upvotes: 5

Related Questions