Example #1
0
        /// <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++;
            }
        }