public bool StartExecution(BackgroundWorker sendingWorker) { if (this.EDFFileStack == null || this.PresentationLogFileStack == null) { throw new ActionCannotDoWhatDoBeDo("No files were presented. Initalise file stack prior to executing!"); } string applicationLogFileName = this.ApplicationLogFileName; int counter = 1; string Holder = applicationLogFileName; while (File.Exists(Holder)) { Holder = Path.GetDirectoryName(applicationLogFileName) + Path.GetFileNameWithoutExtension(applicationLogFileName) + "(" + counter + ")" + Path.GetExtension(applicationLogFileName); counter++; if (counter > 100) { throw new FileNotFoundException("Could not generate an Application Log file after " + counter + " attemtps!"); } } this.ApplicationLogFileName = Holder; ApplicationLogFile = new StreamWriter(this.ApplicationLogFileName); Log("Keeping detailed log in: " + applicationLogFileName, true); int TotalNumberOfFiles = EDFFileStack.Count; while (EDFFileStack.Count > 0) { this.FlushPrevious(); // make absolutely sure nothing of the previous files will be used. try { foreach (BaseAction Action in ActionChain) { if (sendingWorker.CancellationPending) { return(false); } CurrentAction = Action; string Description = CurrentAction.Act(); UpdateProgress(sendingWorker, -1, Description); Log(Description, true); } } catch (ActionCannotDoWhatDoBeDo e) { Log("ERROR: " + e.Message, true); DialogResult Choice = MessageBox.Show(e.Message + "\n\n Do you want to continue with the next file? ", "Critical Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (Choice == DialogResult.No) { break; } UpdateProgress(sendingWorker, (1.0 - (double)EDFFileStack.Count / TotalNumberOfFiles)); } UpdateProgress(sendingWorker, (1.0 - (double)EDFFileStack.Count / TotalNumberOfFiles)); Log(new String('=', 50), true); } UpdateProgress(sendingWorker, -1, "FINISHED!"); ApplicationLogFile.Close(); return(true); }