0

我正在尝试启动并运行 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);

}

有人可以帮我做错什么吗?

4

1 回答 1

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
}
于 2013-10-29T14:09:14.920 回答