Пример #1
0
        // Invoked when application is being started up (before MainWindow creation).
        private void App_Startup(object sender, StartupEventArgs e)
        {
            // Set main thread apartment state.
            Thread.CurrentThread.SetApartmentState(ApartmentState.STA);

            // Set AppUserModelId of current process.
            TaskbarHelper.SetAppUserModelId();

            // Create Mutex if this is first instance.
            try
            {
                RunningInstanceMutex = Mutex.OpenExisting(RunningInstanceMutexName);
            }
            catch (WaitHandleCannotBeOpenedException)
            {
                bool created = false;
                RunningInstanceMutex = new Mutex(false, RunningInstanceMutexName, out created);
                if (!created)
                {
                    throw new Exception("Unable to create application mutex");
                }
            }

            // Load persistent data.
            // Take the first not-switch argument as path to the build that will be imported
            var importedBuildPath = e.Args.FirstOrDefault(s => !s.StartsWith("/"));

            PersistentData = PersistentDataSerializationService.CreatePersistentData(importedBuildPath);

            // Initialize localization.
            L10n.Initialize(PersistentData.Options.Language);
        }
Пример #2
0
        // Invoked when application is being started up (before MainWindow creation).
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            AppDomain.CurrentDomain.UnhandledException +=
                (_, args) => OnUnhandledException((Exception)args.ExceptionObject);

            // Create Mutex if this is first instance.
            try
            {
                _runningInstanceMutex = Mutex.OpenExisting(RunningInstanceMutexName);
            }
            catch (WaitHandleCannotBeOpenedException)
            {
                _runningInstanceMutex = new Mutex(false, RunningInstanceMutexName, out var created);
                if (!created)
                {
                    throw new Exception("Unable to create application mutex");
                }
            }

            // Load persistent data.
            // Take the first not-switch argument as path to the build that will be imported
            var importedBuildPath = e.Args.FirstOrDefault(s => !s.StartsWith("/"));

            PersistentData = PersistentDataSerializationService.CreatePersistentData(importedBuildPath);

            // Initialize localization.
            L10n.Initialize(PersistentData.Options.Language);
        }