Esempio n. 1
0
        protected override void OnStartup(object sender, StartupEventArgs e)
        {
            if (!App.Current.IsShadowProcess)
            {
                // a shadow process is always started by a non-shadow process, which
                // should already have the startup registry value set
                App.Current.SetStartupWithWindows(AppSettings.Default.StartWithWindows);
            }

#if DEBUG && !DEBUG_SINGLE_INSTANCE
            this.DisplayRootViewFor <MainWindowViewModel>();
            return;
#else
            var assemblyLocation = Assembly.GetEntryAssembly().Location;

            var identifier = assemblyLocation.Replace('\\', '_');
            if (!SingleInstance <App> .InitializeAsFirstInstance(identifier))
            {
                Environment.Exit(0);
            }

            if (App.Current.DoNotSpawnShadowExecutable || App.Current.IsShadowProcess)
            {
                this.DisplayRootViewFor <MainWindowViewModel>();
            }
            else
            {
                AppBootstrapper.SpawnShadowProcess(e, assemblyLocation);
                Environment.Exit(0);
            }
#endif
        }
        protected override void OnStartup(object sender, StartupEventArgs e)
        {
            if (!App.Current.IsShadowProcess)
            {
                // a shadow process is always started by a non-shadow process, which
                // should already have the startup registry value set
                App.Current.SetStartupWithWindows(AppSettings.Default.StartWithWindows);
            }

#if DEBUG && !DEBUG_SINGLE_INSTANCE
            this.DisplayRootViewFor <MainWindowViewModel>();
            return;
#else
            var assemblyLocation = Assembly.GetEntryAssembly().Location;

            var identifier = assemblyLocation.Replace('\\', '_');
            if (!SingleInstance <App> .InitializeAsFirstInstance(identifier))
            {
                Environment.Exit(0);
            }

            if (App.Current.DoNotSpawnShadowExecutable || App.Current.IsShadowProcess)
            {
                if (App.Current.IsShadowProcess)
                {
                    AppBootstrapper.UpdateOriginal(e);
                    var checkTimer = new Timer(1000 * 60 * 15);                 // Check for changes every 15 minutes.
                    checkTimer.Elapsed  += (senderTimer, eTimer) => AppBootstrapper.UpdateOriginal(e);
                    checkTimer.AutoReset = true;
                    checkTimer.Enabled   = true;
                }
                this.DisplayRootViewFor <MainWindowViewModel>();
            }
            else
            {
                System.Threading.Thread.Sleep(5000);                 // Wait few seconds to spawn shadow process. It might be still locked after update.
                AppBootstrapper.SpawnShadowProcess(e, assemblyLocation);
                Environment.Exit(0);
            }
#endif
        }