private void закрытиеToolStripMenuItem_Click(object sender, EventArgs e) { String[] filters = new String[2]; filters[0] = "DilationFilter"; filters[1] = "ErosionFilter"; ProcessingTask task = new ProcessingTask(image, filters); backgroundWorker1.RunWorkerAsync(task); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { Bitmap newImage; if (e.Argument is ProcessingTask) { ProcessingTask task = (ProcessingTask)e.Argument; newImage = task.image; for (int i = 0; i < task.filters.Count(); i++) { Filters filter = task.createFilter(task.filters[i]); newImage = filter.processImage(newImage, backgroundWorker1); } } else { newImage = ((Filters)e.Argument).processImage(image, backgroundWorker1); } if (backgroundWorker1.CancellationPending != true) { image = newImage; } }