Prism Module Loading Locks-up Dispatcher Thread. Is There a Way Around This?

后端 未结 1 1218
无人共我
无人共我 2021-01-15 23:01

The Prism application I have performs multiple startup tasks that can take a while and if some of those tasks fail to execute properly it will make the application functiona

相关标签:
1条回答
  • 2021-01-15 23:23

    You have (at least) two options:

    • use a SplashScreen
    • do module initialization on another thread

    Splashscreen example:

    internal class MyBootstrapper
    {
        // [...]
        protected override void InitializeModules()
        {
    
            var splashScreen = new SplashScreen( "myLogo.png" );
            splashScreen.Show( false );
            try
            {
                base.InitializeModules();
            }
            finally
            {
                splashScreen.Close( TimeSpan.Zero );
            }
        }
    }
    

    Tasks example:

    internal class MyBootstrapper
    {
        // [...]
        protected override void InitializeModules()
        {
            Task.Run( () => base.InitializeModules() );
        }
    }
    

    with this, you have to be careful that some services might unexpectedly not be created on the ui thread (e.g. EventAggregator) and those will behave strangely. If that happens, resolve them before kicking off the task that does the initialization.

    0 讨论(0)
提交回复
热议问题