public override void Work(object param) { DeleteFileWrapper wrapper = (DeleteFileWrapper)param; SynchronizationContext context = wrapper.context; List <string> files = wrapper.filesList; foreach (var file in files) { if (running) { try { long size = new FileInfo(file).Length; File.Delete(file); FileDeletedWrapper wrapperResult = new FileDeletedWrapper(); wrapperResult.fileName = file; wrapperResult.size = size; context.Send(FileDeleted, wrapperResult); } catch (Exception) { context.Send(FileNotDeleted, file); } } } context.Send(Finished, running); }
private void Clean() { state = State.Cleaning; MainBtn.Content = "Stop"; deletedFiles = 0; deletedFilesLenght = 0; LogTextBox.Document.Blocks.Clear(); LogTextBox.Document.Blocks.Add(new Paragraph(new Run("Deleting..."))); if (deleteManager == null) { deleteManager = new DeleteFileManager(); deleteManager.OnFileDeleted += FileDeleted; deleteManager.OnFileNotDeleted += FileNotDeleted; deleteManager.OnFinished += CleanFinished; } DeleteFileWrapper wrapper = new DeleteFileWrapper(); wrapper.context = context; wrapper.filesList = filesToDelete; Thread thread = new Thread(deleteManager.Work); thread.Start(wrapper); }