0

I am trying to get the SplashScreenService up and running. It does show my splashscreen, but it doesn't close, never.

I have this code in app.xaml.cs:

protected override void OnStartup(StartupEventArgs e)

{

ServiceLocator.Default.RegisterTypeIfNotYetRegistered<ISplashScreenService, SplashScreenService>();

var splashScreenService = ServiceLocator.Default.ResolveType<ISplashScreenService>();
            splashScreenService.Enqueue(new ActionTask("Task1", tracker => Thread.Sleep(2000)));

splashScreenService.Commit<SplashScreenViewModel>();

base.OnStartup(e);

}

Can anybody help me what I am doing wrong ?

andrewsi
  • 10,807
  • 132
  • 35
  • 51

1 Answers1

1

Seems like you are blocking the UI thread please try in this way:

public partial class App
{
    #region Methods

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        var splashScreenService = ServiceLocator.Default.ResolveType<ISplashScreenService>();
        splashScreenService.Enqueue(new ActionTask("Task1", tracker => Thread.Sleep(2000)));
        splashScreenService.Enqueue(new ActionTask("Task2", tracker => Thread.Sleep(2000)));
        splashScreenService.Enqueue(new ActionTask("Task3", tracker => Thread.Sleep(2000)));
        splashScreenService.CommitAsync();
    }

    #endregion
}

or for your custom splash screen

public partial class App
{
    #region Methods

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        var splashScreenService = ServiceLocator.Default.ResolveType<ISplashScreenService>();
        splashScreenService.Enqueue(new ActionTask("Task1", tracker => Thread.Sleep(2000)));
        splashScreenService.Enqueue(new ActionTask("Task2", tracker => Thread.Sleep(2000)));
        splashScreenService.Enqueue(new ActionTask("Task3", tracker => Thread.Sleep(2000)));
        splashScreenService.CommitAsync<SplashScreenViewModel>();
    }

    #endregion
}
  • Thanks, example 1 does cause an exception: Cannot set Owner property to a Window that has not been shown previously. Example 2 shows briefly the splashscreen and with a second the main screen. After a few seconds the splashscreen and mainscreen are closed automatically. I am looking for a solution to show the splashscreen, do some initialisation stuff, after the initialisation I want to load the mainscreen and when the mainscreen is loaded, close the splashscreen. Is this possible ? – user2932373 Oct 31 '13 at 08:19
  • For the examples I used the 3.7 stable version. Yes, it is possible. This feature cover such scenario. – Igr Alexánder Fernández Saúco Oct 31 '13 at 14:46