/// <summary> /// 移动文件 /// </summary> private void MoveFile() { int index = dgFiles.SelectedIndex; if (index == -1 || index >= FoundFiles.Count) { return; } if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { String FileName = FoundFiles[index].Name; String ChoosedFile = FoundFiles[index].Location + @"\\" + FileName; String toDir = folderBrowserDialog.SelectedPath; String toDirFile = toDir.EndsWith("\\") ? toDir + FileName : toDir + @"\\" + FileName; //不允许再进行文件操作 //EnableButton(false); //异步执行文件移动 Task tsk = new Task(() => { Action del = () => { win = new ShowFileCopyOrMove(); win.Information = "\"" + FileName + "\"正在移动中..."; win.Show(); }; Dispatcher.Invoke(del); File.Move(ChoosedFile, toDirFile); FoundFiles[index].Location = toDir; // Dispatcher.Invoke(showInfo, "\"" + FileName + "\"文件移动完成"); del = () => { win.Close(); win = null; }; //Action<bool> del = EnableButton; //Dispatcher.Invoke(del, true); Dispatcher.Invoke(del); }); tsk.Start(); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.ToString()); } } }
/// <summary> /// 移动文件 /// </summary> private void MoveFile() { int index = dgFiles.SelectedIndex; if (index == -1 || index >= FoundFiles.Count) { return; } if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { String FileName = FoundFiles[index].Name; String ChoosedFile = FoundFiles[index].Location + @"\\" + FileName; String toDir = folderBrowserDialog.SelectedPath; String toDirFile = toDir.EndsWith("\\") ? toDir + FileName : toDir + @"\\" + FileName; //不允许再进行文件操作 //EnableButton(false); //异步执行文件移动 Task tsk = new Task(() => { Action del = () => { win = new ShowFileCopyOrMove(); win.Information = "\"" + FileName + "\"正在移动中..."; win.Show(); }; Dispatcher.Invoke(del); File.Move(ChoosedFile, toDirFile); FoundFiles[index].Location = toDir; // Dispatcher.Invoke(showInfo, "\"" + FileName + "\"文件移动完成"); del = () => { win.Close(); win = null; }; //Action<bool> del = EnableButton; //Dispatcher.Invoke(del, true); Dispatcher.Invoke(del); }); tsk.Start(); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.ToString()); } } }