Пример #1
0
        /// <summary>
        /// System.Windows.Application.Startup イベント を発生させます。
        /// </summary>
        /// <param name="e">イベントデータ を格納している StartupEventArgs</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            Process currentProcess = Process.GetCurrentProcess();
            var     nameProcess    = currentProcess.ProcessName;
            var     regex          = new Regex(@"^(\w+)\.vshost$");

            if (regex.IsMatch(nameProcess))
            {
                var match = regex.Match(nameProcess);
                nameProcess = match.Groups[1].Captures[0].Value;
            }
            var processes      = Process.GetProcesses();
            var runningProcess = (from process in Process.GetProcesses()
                                  where
                                  process.Id != currentProcess.Id &&
                                  process.ProcessName.Equals(
                                      nameProcess,
                                      StringComparison.Ordinal)
                                  select process).FirstOrDefault();

            if (runningProcess != null)
            {
                ShowWindow(runningProcess.MainWindowHandle, SW_SHOWNORMAL);
                Application.Current.Shutdown();
                return;
            }

            base.OnStartup(e);
            this.ShutdownMode      = ShutdownMode.OnExplicitShutdown;
            this.wrapperIconNotify = new NotifyIconWrapper();
        }
Пример #2
0
        /// <summary>
        /// System.Windows.Application.Startup イベント を発生させます。
        /// </summary>
        /// <param name="e">イベントデータ を格納している StartupEventArgs</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            Process currentProcess = Process.GetCurrentProcess();
            var nameProcess = currentProcess.ProcessName;
            var regex = new Regex(@"^(\w+)\.vshost$");
            if (regex.IsMatch(nameProcess)) {
                var match = regex.Match(nameProcess);
                nameProcess = match.Groups[1].Captures[0].Value;
            }
            var processes = Process.GetProcesses();
            var runningProcess = (from process in Process.GetProcesses()
                                  where
                                    process.Id != currentProcess.Id &&
                                    process.ProcessName.Equals(
                                      nameProcess,
                                      StringComparison.Ordinal)
                                  select process).FirstOrDefault();
            if (runningProcess != null) {
                ShowWindow(runningProcess.MainWindowHandle, SW_SHOWNORMAL);
                Application.Current.Shutdown();
                return;
            }

            base.OnStartup(e);
            this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
            this.wrapperIconNotify = new NotifyIconWrapper();
        }