title: How can I make timer2 and timer3 to work at the same time but asynchrony?
body: <p>I have a timer3 tick event:</p>
  
  <pre><code>private void timer3_Tick(object sender, EventArgs e)
          {
              pictureBox1.Invalidate();
          }
  </code></pre>
  
  <p>Timer3 interval set to 10ms. It's going to the paint event of pictureBox1 and draw something.</p>
  
  <p>And then I have timer2 tick event:</p>
  
  <pre><code>private void timer2_Tick(object sender, EventArgs e)
          {
              label1.Visible = true;
              if (counter == 200)
              {
                  timer2.Enabled = false;
                  return;
              }
              counter += 1;
              distance = (float)counter;
              CloudEnteringAlert.cloudalert(bitmapwithclouds, distance);
              double d = double.Parse(CloudEnteringAlert.cloudsdistance.Text, CultureInfo.InvariantCulture);
              string s = string.Format("{0:0.0}", d);
              if (CloudEnteringAlert.cloudsfound == true)
              {
                  label2.Visible = true;
                  timer1.Enabled = true;
                  listBox1.Items.Add("Cloud detected at: " + CloudEnteringAlert.cloudsdistance.Text + " Kilometers from the coast");
                  timesdetectedclouds += 1;
                  label2.Text = timesdetectedclouds.ToString();
                  if (CloudEnteringAlert.cloudsdistance.Text == "0")
                  {
  
                  }
                  else
                  {
                      if (CloudEnteringAlert.cloudsfound == false)
                      {
  
                      }
                  }
              }
              else
              {
                  double dd = double.Parse(CloudEnteringAlert.cloudsdistance.Text, CultureInfo.InvariantCulture);
                  string ss = string.Format("{0:0.0}", d);
                  listBox1.Items.Add("Cloud not detected at: " + CloudEnteringAlert.cloudsdistance.Text + " Kilometers from the coast");
                  timesnotdetectedclouds += 1;
                  label4.Text = timesnotdetectedclouds.ToString();
              }
          }
  </code></pre>
  
  <p>timer2 interval is set to 1000ms</p>
  
  <p>The problem is when timer2 and timer3 are working the same time the drawings in the paint event of pictureBox1 are going very slow and only when timer2 stop then timer3 is realy on 10ms speed.</p>
  
  <p>The question is how to make that both timers will work on the same time but each one with it's own real time? To put timer3 in a backgroundworker? If so how to do it with the backgroundworker?</p>
  
  <p>This is pictureBox1 paint event:</p>
  
  <pre><code>private void pictureBox1_Paint(object sender, PaintEventArgs e)
          {
              anglecounter += 1;
              DrawLine(e.Graphics, anglecounter);
              if (null != mImage)
              {
                  e.Graphics.DrawImage(mImage, mRect);
              }
              DrawRectangle(e.Graphics);
          }
  </code></pre>
  
  <p>This is the DrawLine method:</p>
  
  <pre><code>private void DrawLine(Graphics g, double angle)
          {
  
              Pen pen = new Pen(Color.Red, 2f);
              int r = pictureBox1.Size.Width / 2;
              int X1 = pictureBox1.Size.Width / 2;
              int Y1 = pictureBox1.Size.Height / 2;
              Point pStart = new Point(X1, Y1);
              int X2 = (int)(X1 + r * Math.Cos((double)angle * Math.PI / 180));
              int Y2 = (int)(Y1 + r * Math.Sin((double)angle * Math.PI / 180));
              Point pEnd = new Point(X2, Y2);
              g.DrawEllipse(new Pen(Color.Red, 2f), 0, 0, pictureBox1.Size.Width, pictureBox1.Size.Height);
              Rectangle rec = new Rectangle(0, 0, pictureBox1.Size.Width, pictureBox1.Size.Height);
              path = new GraphicsPath();
              path.AddPie(rec, (int)angle, -50);
              PathGradientBrush brush = new PathGradientBrush(path);
              brush.CenterPoint = pStart;
              brush.CenterColor = Color.LightGreen;
              brush.SurroundColors = new Color[] { Color.Empty };
              g.FillPath(brush, path);
  
          } 
  </code></pre>
  
  <p>And the DrawRectangle method:</p>
  
  <pre><code>private void DrawRectangle(Graphics e)
          {
              using (Pen pen = new Pen(Color.Red, 2))
              {
                  e.DrawRectangle(pen, mRect);
              }
          }
  </code></pre>
  
  <p>The draw rectangle if i want i'm drawing it manualy a rectangle on the pictureBox1.
  The drawline method is drawing like a doppler radar and i want it to animate/move all the time aorund so that's why i'm using timer3 10ms and invalidating pictureBox1.</p>
  
  <p>timer2 does something else it's doing another task i need to detect some pixels over the radar.</p>