コード例 #1
0
        private void App_Startup(object sender, StartupEventArgs e)
        {
            try
            {
                var processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
                var process     = System.Diagnostics.Process.GetProcessesByName(processName);
                if (process.Length > 1)
                {
                    MessageBox.Show("已经有一个实例在运行!");
                    Shutdown();
                    return;
                }
                StartupUri   = new Uri("MainWindow.xaml", UriKind.Relative);
                ShutdownMode = ShutdownMode.OnLastWindowClose;

                Settings = BaseSettings.Load();
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("程序运行故障:{0}", ex.Message));
                Logger.ErrorLoger.Log(ex.ToString());
                Shutdown();
            }
        }