private static void DeleteFiles(IEnumerable <Redistributables> redistributables, ProgressBar progressBar, DialogSession dialogSession) { Task.Factory.StartNew(() => { var failures = new List <string>(); foreach (var item in redistributables.Select((red, idx) => new { red, idx })) { progressBar.Dispatcher.BeginInvoke(new Action(() => progressBar.Value = item.idx)); try { if (File.Exists(item.red.Path)) { File.Delete(item.red.Path); } } catch { failures.Add(item.red.Path); } } if (failures.Count > 0) { progressBar.Dispatcher.BeginInvoke(new Action(() => { var failuresDialog = new FailuresDialog { FailuresListBox = { ItemsSource = failures } }; dialogSession.UpdateContent(failuresDialog); })); } else { progressBar.Dispatcher.BeginInvoke(new Action(dialogSession.Close)); } }); }
private static void DeleteFiles(IEnumerable<Redistributables> redistributables, ProgressBar progressBar, DialogSession dialogSession) { Task.Factory.StartNew(() => { var failures = new List<string>(); foreach (var item in redistributables.Select((red, idx) => new {red, idx})) { progressBar.Dispatcher.BeginInvoke(new Action(() => progressBar.Value = item.idx)); try { if (File.Exists(item.red.Path)) File.Delete(item.red.Path); } catch { failures.Add(item.red.Path); } } if (failures.Count > 0) progressBar.Dispatcher.BeginInvoke(new Action(() => { var failuresDialog = new FailuresDialog {FailuresListBox = {ItemsSource = failures}}; dialogSession.UpdateContent(failuresDialog); })); else progressBar.Dispatcher.BeginInvoke(new Action(dialogSession.Close)); }); }