Beispiel #1
0
 /// <summary>
 /// 刷新列表
 /// </summary>
 private void RefreshListView()
 {
     SaveTasks();
     background.Dispose();
     background = new BackgroundWork();
 }
Beispiel #2
0
        protected async override void OnStartup(StartupEventArgs e)
        {
#if !DEBUG
            //base.OnStartup(e);
            new WpfCodes.Program.Exception().UnhandledException += (p1, p2) =>
            {
                try
                {
                    Dispatcher.Invoke(() => WpfControls.Dialog.DialogHelper.ShowException("程序发生了未捕获的错误,类型" + p2.Source.ToString(), p2.Exception));

                    File.AppendAllText("Exception.log", Environment.NewLine + Environment.NewLine + DateTime.Now.ToString() + Environment.NewLine + p2.Exception.ToString());
                }
                catch (Exception ex)
                {
                    Dispatcher.Invoke(() => WpfControls.Dialog.DialogHelper.ShowException("错误信息无法写入", ex));
                }
                finally
                {
                    App.Current.Shutdown();
                }
            };


            if (await WpfCodes.Program.Startup.CheckAnotherInstanceAndOpenWindow <MainWindow>("FileBackuper", this))
            {
                return;
            }
#endif
            string configFile = "FileBackuperConfig.json";
            try
            {
                set = Settings.GetJsonSetting <Settings>(configFile);
            }
            catch (Exception ex)
            {
                WpfControls.Dialog.DialogHelper.ShowException("读取配置文件失败,将重置配置文件", ex, true);
                set = Settings.CreatJsonSetting <Settings>(configFile);
            }
            background = new BackgroundWork();


            if (!(e.Args.Length == 1 && e.Args[0] == "noWindow"))
            {
                MainWindow = new MainWindow();
                MainWindow.Show();
                MainWindow.Closed += (p1, p2) =>
                {
                    MainWindow = null;
                };
            }

            Dictionary <string, Action> trayRightButtonActions = new Dictionary <string, Action>()
            {
                { "退出", TryExit }
            };


            tray = new WpfCodes.Program.TrayIcon(FileBackuper.Properties.Resources.Icon, "文件自动备份系统", TrayOpenWindow, trayRightButtonActions);
            tray.Show();
            background.timer.Start();


            void TrayOpenWindow()
            {
                if (MainWindow == null)
                {
                    MainWindow = new MainWindow();
                    MainWindow.Show();
                }
            }
        }