SplashScreenService doesn't work as I want

2019-08-26 14:47发布

问题:

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 ?

回答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
}


标签: catel