public static DialogResult process( IList <TItem> batch, BatchItemProcessor <TItem> batchItemProcessor, String titleText, String progressTextStatusPattern, IWin32Window ownerWindow ) { using (BatchProcessingForm <TItem> batchProcessingForm = new BatchProcessingForm <TItem>(batch, batchItemProcessor, titleText, progressTextStatusPattern)) { return(batchProcessingForm.ShowDialog(ownerWindow)); } }
private BatchProcessingForm(IList <TItem> batch, BatchItemProcessor <TItem> batchItemProcessor, String titleText, String progressTextStatusPattern) { this.batch = batch; this.batchItemProcessor = batchItemProcessor; Text = titleText; StartPosition = FormStartPosition.CenterParent; ClientSize = new Size(600, 500); FormBorderStyle = FormBorderStyle.FixedDialog; ShowInTaskbar = false; this.appendControls( logTextBox = new TextBox() { ReadOnly = true, Multiline = true, ScrollBars = ScrollBars.Both, WordWrap = false, Dock = DockStyle.Fill }, progressBar = new ProgressBar() { Value = 0, Step = 1, Dock = DockStyle.Bottom }, progressLabel = new Label() { TextAlign = ContentAlignment.MiddleCenter, Dock = DockStyle.Bottom, Text = String.Format(progressTextStatusPattern, 0) }, new Panel() { Dock = DockStyle.Bottom, Height = 30, Padding = new Padding(4) }.withControls( new Button() { Text = "Stop", Dock = DockStyle.Right, TabIndex = 1 }.withAction(stop) ) ); logTextBoxWriter = new TextBoxWriter(logTextBox); backgroundWorker = new BackgroundWorker() .withCancellationSupport() .withProgressReportsTo(progressBar) .withProgressReportsTo(progressLabel, progressTextStatusPattern) .withWork <Object, Object, BackgroundWorker>(doWork) .whenCompleted(onBackgroundWorkerRunWorkerCompleted); }