SplashScreenService无法正常工作

时间:2013-10-29 13:46:06

标签: catel

我正在尝试启动并运行SplashScreenService。它确实显示我的闪屏,但它不会关闭,永远不会。

我在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);

}

有人可以帮我解决我做错的事吗?

1 个答案:

答案 0 :(得分:1)

好像你正在阻止UI线程请尝试这样:

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
}

或自定义初始屏幕

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
}