Пример #1
0
        /// <summary>
        /// 关闭前处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window1_OnClosing(object sender, CancelEventArgs e)
        {
            //保存所有便签设置
            NotepadManage.SaveSetings(this);

            //Application.Current.MainWindow
            try
            {
                RichTextBoxTool.Writer(RichTextBox1, CacheFileName);

                //如果ShowInTaskbar设置为true,则关闭时先关闭子窗体
                //如果设置为false,则先关闭主窗体
                //if (!ShowInTaskbar)
                NotepadManage.RemoveNotepad(this);

                NotepadManage.ShowWindowListCount--;
                if (NotepadManage.ShowWindowListCount == 0)
                {
                    //关闭一个应用程序。
                    SystemCommon.ExitSystem();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("保存出了点问题..." + ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                e.Cancel = true;
            }
        }
Пример #2
0
        /// <summary>
        /// 窗体关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainWindow_OnClosing(object sender, CancelEventArgs e)
        {
            //保存设置
            _settings.Title       = Title;
            _settings.WinLocation = new Point(Left, Top);
            _settings.Save();

            //保存所有便签设置--已经在APP中设置
            NotepadManage.SaveSetings();

            //关闭一个应用程序。
            SystemCommon.ExitSystem();
        }
Пример #3
0
        public App()
        {
            #region  序退出异常处理

            var pro = Process.GetCurrentProcess();
            pro.EnableRaisingEvents = true;

            pro.Exited += (sender, e1) =>
            {
                ToolLogs.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "在进程退出时发生");
            };

            AppDomain.CurrentDomain.ProcessExit += (sender, e1) =>
            {
                ////晚于this.Exit
                //System.Threading.Monitor.TryEnter(obj, 500);
                ////后来改为
                //System.Threading.Monitor.Enter(obj);

                ToolLogs.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "当默认应用程序域的父进程存在时发生");

                ////不能在这保存所有便签设置,因为这时所有的程序已经全部关闭。
                //NotepadManage.SaveSetings();
            };

            //异常处理
            this.DispatcherUnhandledException += (sender, e1) =>
            {
                ToolLogs.Debug(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "系统异常处理", e1.Exception);

                e1.Handled = true;//使用这一行代码告诉运行时,该异常被处理了,不再作为UnhandledException抛出了。
                SystemCommon.IsExitSystem = true;

                MessageBox.Show("我们很抱歉,当前应用程序遇到一些问题,该操作已经终止,将要重新启动。" + e1.Exception.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);//这里通常需要给用户一些较为友好的提示,并且后续可能的操作


                //保存所有便签设置
                NotepadManage.SaveSetings();

                //不要在这打开程序,如果你的程序是刚打开时出现错误,用户将无法关闭。这将是用户的恶梦。
                SystemCommon.ExitSystem();
                //System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
            };

            this.Exit += (sender, e1) =>
            {
                //早于AppDomain.CurrentDomain.ProcessExit
                ToolLogs.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "在进程退出时发生Exit");
                ////不能在这保存所有便签设置,因为这时所有的程序已经全部关闭。
                // NotepadManage.SaveSetings();
                //e1.ApplicationExitCode
            };

            #endregion

            bool result = ImputCacheFile();

            //非调试模式
            if (!System.Diagnostics.Debugger.IsAttached)
            {
                Client.Pub.ServiceProxyFactoryLib.ProxyBinding.ReplaceAddress = true;
                Client.Pub.ServiceProxyFactoryLib.ProxyBinding.ReplacePort    = true;

                //检测是否已有一个程序实例运行
                this.Startup += new StartupEventHandler(App_Startup);


                //下载版本不同的文件
                string loadPath = Path.Combine(SystemCommon.Path, "AutoUpdate");

                //复制自动更新程序文件
                Tools.FileManage.CopyDir(Path.Combine(loadPath, "LoadDown\\AutoUpdate\\"), loadPath);

                Tools.FileManage.IsUpdateThread();

                //绑定扩展名
                Task task = new Task(() =>
                {
                    try
                    {
                        BindingExtend();
                    }
                    catch (Exception e)
                    {
                        ToolLogs.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "绑定扩展名", e);
                    }
                });
                task.Start();
            }
        }