title: Thread not working properly
body: <p>I made a program on stenography which is working properly but NOT RESPONDING when large text files are used. I need to implement threads to it. 
  It tried with the below code but still it gave me the same problem.
  Don't know actually where i made mistake.
  also i need to add a progress bar, but don't know where to add the code.</p>
  
  <pre><code>private void button3_Click(object sender, EventArgs e)
      {
          Thread myThread = new System.Threading.Thread(delegate()
          {
              RUN();
                  for (int n = 0; n &lt; 100; n++)
                  {
                      Thread.Sleep(50);
                      progressBar1.BeginInvoke(new Action(() =&gt; progressBar1.Value = n));
                  }
          });
          myThread.Start();
      }
      private void RUN()
      {
          if (this.InvokeRequired)
          {
              this.BeginInvoke((MethodInvoker)delegate()
              {
                  int ascii;
                  String xor;
                  String text = textBox1.Text;
                  if (textBox1.Text != "")
                  {
                      Bitmap bitmap = (Bitmap)pictureBox1.Image;
                      Bitmap bmp = (Bitmap)pictureBox1.Image;
                      //richTextBox1.Text = "\n";
                      byte[] asciiBytes = Encoding.ASCII.GetBytes(textBox1.Text);// Convert the string into a byte[].
                      int x0 = 0, y0 = 0;
                      // Error checking, to see if text can fit in image
                      int imageSize = bitmap.Width * bitmap.Height;
                      if (imageSize - x0 * bitmap.Width - y0 &lt; 8 * textBox1.Text.Length)
                      {
                          MessageBox.Show("Too Large");
                      }
                      for (int t = 0; t &lt; textBox1.Text.Length; t++)
                      {
                          ascii = asciiBytes[t];
                          xor = program.binlength(Convert.ToString(ascii ^ 254, 2));
                          //richTextBox1.Text = richTextBox1.Text + xor + "\n";   
                          for (int i = 0; i &lt; 8; i++)
                          {
                              // Check if y0 has exceeded image width
                              // so to wrap around to the new row
                              if (y0 == bitmap.Width)
                              {
                                  x0++;
                                  y0 = 0;
                              }
                              hide(bmp, bitmap, y0, x0, i,xor);
                              // x0, y0 are now the current pixel coordinates
                              //
                              // EMBED MESSAGE HERE
                              //
                              y0++;  // Move to the next pixel for the next bit
                          }
                      }
  
                      MessageBox.Show("" + (text.Length * 8));
                  }
                  else
                      MessageBox.Show("Text???");
              });
          }
      }
  private void hide(Bitmap bmp, Bitmap bitmap,int y0,int x0,int i,string xor)
      {  
          Color colorpixel,newcolor;
          String pixR;
          colorpixel = bitmap.GetPixel(y0, x0);
          pixR = program.binlength(Convert.ToString(Convert.ToInt32(colorpixel.R), 2));
          newcolor = Color.FromArgb(Convert.ToByte(program.converttopixcel(xor, pixR, i), 2), colorpixel.G, colorpixel.B);
          bmp.SetPixel(y0, x0, newcolor);
          pictureBox2.Image = bmp;
      }
  </code></pre>
  
  <p>Thank You.  </p>