private void startGeneration(object _sender, DoWorkEventArgs _event) { int numBitmaps, count = 1; Bitmap bmp; Bitmap[] bitmaps; BackgroundWorker worker = _sender as BackgroundWorker; decimal numberOfPlaceholder = 0; foreach (Section s in m_sections) { numberOfPlaceholder += s.NumberOfPlaceholder; } foreach (Section s in m_sections) { if (worker.CancellationPending) { _event.Cancel = true; break; } else { bitmaps = GenerateSection(s); numBitmaps = bitmaps.Length; for (int i = 0; i < numBitmaps; i++, count++) { bmp = bitmaps[i]; if (s.Auto) { Save(bmp, s.Filename, s.Prefix, s.Suffix, i); } else { FileSection fs = s.Files[i]; Save(bmp, fs.Filename, s.Prefix, s.Suffix); } Thread.Sleep(100); int percent = count * 100 / (int)numberOfPlaceholder; worker.ReportProgress(percent); if (worker.CancellationPending) { _event.Cancel = true; break; } } } } }
private Bitmap[] GenerateSection(Section _section) { List <Bitmap> bitmaps = new List <Bitmap>(); for (int i = 0; i < _section.NumberOfPlaceholder; i++) { if (_section.Auto) { bitmaps.Add(CreatePlaceholder(_section, _section.Text)); } else { FileSection fs = _section.Files[i]; bitmaps.Add(CreatePlaceholder(_section, fs.Text)); } } return(bitmaps.ToArray()); }