private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { string secondDirPath = null; try { var dir = new DirectoryInfo(folderBrowserDialog2.SelectedPath); secondDirPath = dir.FullName; } catch (Exception) { Console.WriteLine($"Error: folderBrowserDialog2 don`t entered"); } var userOptions = new UserOptions(GetFolding(), GetTitle(), moveToFolderCheckBox.Checked, secondDirPath); var mp3Files = new DirectoryInfo(folderBrowserDialog1.SelectedPath) .GetFiles("*.mp3", SearchOption.AllDirectories); var fileOperator = new FileOperator(userOptions); for (int i = 0; i < mp3Files.Length; i++) { fileOperator.SetTarget(mp3Files[i]); fileOperator.DoStuff(); int percentage = (i + 1) * 100 / mp3Files.Length; backgroundWorker1.ReportProgress(percentage); } }
public FileOperator(UserOptions userOptions) { _userOptions = userOptions; }