private async void Button_Click_2(object sender, RoutedEventArgs e) { Button button = (Button)sender; button.IsEnabled = false; cts = new CancellationTokenSource(); cts.Token.Register(() => { HandyControl.Controls.Growl.Info(Jvedio.Language.Resources.Cancel, GrowlToken); }); ct = cts.Token; //数据库管理 var cb = CheckBoxWrapPanel.Children.OfType <CheckBox>().ToList(); string path = $"DataBase\\{vieModel_DBManagement.CurrentDataBase}"; MySqlite db = new MySqlite(path); if ((bool)cb[0].IsChecked) { //重置信息 db.DeleteTable("movie"); db.CreateTable(DataBase.SQLITETABLE_MOVIE); //清空最近播放和最近创建 ClearDateBefore(DateTime.Now); db.Vacuum(); HandyControl.Controls.Growl.Success(Jvedio.Language.Resources.Message_Success, GrowlToken); } if ((bool)cb[1].IsChecked) { //删除不存在影片 long num = 0; await Task.Run(() => { var movies = db.SelectMoviesBySql("select * from movie"); try { vieModel_DBManagement.ProgressBarValue = 0; for (int i = 0; i < movies.Count; i++) { ct.ThrowIfCancellationRequested(); if (!File.Exists(movies[i].filepath)) { db.DeleteByField("movie", "id", movies[i].id); num++; } if (movies.Count > 0) { vieModel_DBManagement.ProgressBarValue = (int)((double)(i + 1) / (double)movies.Count * 100); } } db.Vacuum(); } catch (OperationCanceledException ex) { Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {ex.Message}"); } }, ct); HandyControl.Controls.Growl.Success($"{ Jvedio.Language.Resources.SuccessDelete} {num}", GrowlToken); } if ((bool)cb[2].IsChecked) { var movies = db.SelectMoviesBySql("select * from movie"); StringCollection ScanPath = ReadScanPathFromConfig(vieModel_DBManagement.CurrentDataBase); long num = 0; await Task.Run(() => { try { vieModel_DBManagement.ProgressBarValue = 0; for (int i = 0; i < movies.Count; i++) { ct.ThrowIfCancellationRequested(); if (!IsPathIn(movies[i].filepath, ScanPath)) { db.DeleteByField("movie", "id", movies[i].id); num++; } if (movies.Count > 0) { vieModel_DBManagement.ProgressBarValue = (int)((double)(i + 1) / (double)movies.Count * 100); } } db.Vacuum(); } catch (OperationCanceledException ex) { Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {ex.Message}"); } }, ct); HandyControl.Controls.Growl.Success($"{Jvedio.Language.Resources.SuccessDelete} {num}", GrowlToken); } if ((bool)cb[3].IsChecked) { if (Properties.Settings.Default.SaveInfoToNFO) { var detailMovies = db.SelectDetailMoviesBySql("select * from movie"); await Task.Run(() => { try { vieModel_DBManagement.ProgressBarValue = 0; for (int i = 0; i < detailMovies.Count; i++) { ct.ThrowIfCancellationRequested(); FileProcess.SaveNfo(detailMovies[i]); if (detailMovies.Count > 0) { vieModel_DBManagement.ProgressBarValue = (int)((double)(i + 1) / (double)detailMovies.Count * 100); } } } catch (OperationCanceledException ex) { Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {ex.Message}"); } }, ct); HandyControl.Controls.Growl.Success($"{Jvedio.Language.Resources.Message_Success}", GrowlToken); } else { HandyControl.Controls.Growl.Success($"{Jvedio.Language.Resources.setnfo}", GrowlToken); } } db.CloseDB(); cts.Dispose(); await Task.Run(() => { Task.Delay(500).Wait(); }); Main main = (Main)GetWindowByName("Main"); main?.vieModel.Reset(); button.IsEnabled = true; }