Ejemplo n.º 1
0
            void InternalThreadEntryPoint(object parameter)
            {
                Func <object, Window> windowCreator       = ((object[])parameter)[0] as Func <object, Window>;
                Func <object, object> splashScreenCreator = ((object[])parameter)[1] as Func <object, object>;
                object windowCreatorParameter             = ((object[])parameter)[2];
                object splashScreenCreatorParameter       = ((object[])parameter)[3];
                var    lockMode = (UIThreadReleaseMode?)SplashScreenHelper.FindParameter(parameter, UIThreadReleaseMode);
                var    info     = SplashScreenHelper.FindParameter <SplashScreenInfo>(parameter) ?? ActiveInfo;

#if DEBUGTEST || DEBUG
                if (info.WaitEvent != null)
                {
                    info.WaitEvent.WaitOne(2000);
                }
#endif
                info.SplashScreen = windowCreator(windowCreatorParameter);
                info.Dispatcher   = info.SplashScreen.Dispatcher;
                info.Callbacks.Initialize();
                if (SplashScreenHelper.IsResourcesLocked())
                {
                    lockMode = null;
                    SyncEvent.Set();
                }

                splashScreenCreator.Do(x => info.SplashScreen.Content = x(splashScreenCreatorParameter));
                SetProgressStateCore(info, true);
                info.InitializeOwner(parameter);
                SubscribeParentEvents(windowCreatorParameter);
                if (lockMode.HasValue && lockMode.Value == UIThreadReleaseMode.WaitForSplashScreenInitialized)
                {
                    SyncEvent.Set();
                }

                info.Callbacks.ExecuteExceptClose();
                bool skipOpen = info.CloseWithParent && info.RelationInfo.Return(x => x.ActualIsParentClosed, () => false);
#if DEBUGTEST || DEBUG
                Test_SkipWindowOpen = skipOpen;
#endif
                bool unlockRequired = lockMode.HasValue && lockMode.Value == UIThreadReleaseMode.WaitForSplashScreenLoaded;
                if (!skipOpen)
                {
                    if (unlockRequired)
                    {
                        info.SplashScreen.Loaded += OnSplashScreenLoaded;
                    }
                    PatchSplashScreenWindowStyle(info.SplashScreen, info.Owner != null);
                    info.Callbacks.ExecuteClose();
                    info.SplashScreen.ShowDialog();
                    if (unlockRequired)
                    {
                        info.SplashScreen.Loaded -= OnSplashScreenLoaded;
                    }
                    info.ActivateOwner();
                }
                else if (unlockRequired)
                {
                    SyncEvent.Set();
                }

                ReleaseResources(info);
            }