Splash Screen Timer

2019-07-31 15:20发布

问题:

I actually try to add a Splash Screen to my WPF application. It is quite easy:

SplashScreen s = new SplashScreen("/Images/Agrar.png");
s.Show(true);

My problem is, that I want the Splash Screen to show about 10sec, but my Application doesn´t need so long to load.

So I thought about the Timer class and tried a bit, but I don´t know how to combine it with a Splash Screen. Is there a better solution? How does it work with Timer? Because I didn´t find a option to say, what should happen while the Timer is running.

回答1:

You can try putting your main thread to sleep for 10 seconds (if splash is visible, users won't use your app anyway), or fade out the splash over a period of time:

    SplashScreen splash = new SplashScreen("/Images/Agrar.png");
    splash.Show(false);
    Thread.Sleep(10000);
    splash.Close( TimeSpan.FromSeconds(20)); //fade out over 20 seconds


回答2:

The best way and using the API is

  SplashScreen splash = new SplashScreen("splashscreen.jpg");
  splash.Show(false);
  splash.Close(TimeSpan.FromMilliseconds(2));
  InitializeComponent();