/// <summary> /// Called by the background worker each time a corrupted image is created /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FileCorruptBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { //Trace.WriteLine("FileCorruptBackgroundWorker_ProgressChanged()"); FileCorruptBackgroundWorkerUserState state = e.UserState as FileCorruptBackgroundWorkerUserState; _offscreenBitmap = state.Bitmap; //Trace.Assert(_offscreenBitmap != null); toolStripLabelCurrent.Text = state.Word; if (!toolStripProgressBar.IsDisposed) { if (toolStripProgressBar.Value != e.ProgressPercentage) { Trace.WriteLine(e.ProgressPercentage + "% complete"); } toolStripProgressBar.Value = e.ProgressPercentage; } //Trace.WriteLine("Calling Invalidate"); this.Invalidate(); }
/// <summary> /// Worker method for the background worker. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FileCorruptBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { Trace.WriteLine("FileCorruptBackgroundWorker_DoWork()"); FileCorruptBackgroundWorkerUserState UserState = new FileCorruptBackgroundWorkerUserState(); int n = 1; foreach (string word in _wordList) { if (FileCorruptBackgroundWorker.CancellationPending) { Trace.WriteLine("FileCorruptBackgroundWorker.CancellationPending"); return; } //Trace.WriteLine("_corruptionMode: " + _corruptionMode.ToString()); switch (_corruptionMode) { case CorruptionMode.Random: // This will block if needed CorruptImageBytesRandom(_bytes, word); break; case CorruptionMode.Sequential: // This will block if needed CorruptImageBytesSequential(_bytes, word); break; } // Render to a bitmap for fast blitting //Trace.WriteLine("Render to bitmap..."); UserState.Bitmap = PaintBitmap(_bytes); UserState.Word = word; int percent = (int)((double)n * 100 / _wordList.Count); FileCorruptBackgroundWorker.ReportProgress(percent, UserState); n++; } }
/// <summary> /// Worker method for the background worker. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FileCorruptBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { Trace.WriteLine("FileCorruptBackgroundWorker_DoWork()"); FileCorruptBackgroundWorkerUserState UserState = new FileCorruptBackgroundWorkerUserState(); int n = 1; foreach (string word in _wordList) { if (FileCorruptBackgroundWorker.CancellationPending) { Trace.WriteLine("FileCorruptBackgroundWorker.CancellationPending"); return; } //Trace.WriteLine("_corruptionMode: " + _corruptionMode.ToString()); switch (_corruptionMode) { case CorruptionMode.Random: // This will block if needed CorruptImageBytesRandom(_bytes, word); break; case CorruptionMode.Sequential: // This will block if needed CorruptImageBytesSequential(_bytes, word); break; } // Render to a bitmap for fast blitting //Trace.WriteLine("Render to bitmap..."); UserState.Bitmap = PaintBitmap(_bytes); UserState.Word = word; int percent = (int)((double)n * 100 / _wordList.Count); FileCorruptBackgroundWorker.ReportProgress(percent, UserState); n++; } }