title: Averaging serial data stream values
body: <p>I have a stream of data at approx. 500 Hz coming from serial port. The data are sent by a microprocessor which is controlling a machine. The data are filtered out and shown in different text boxes by a class that strips out the header characters used by the transmission protocol.
  This is the code that assigns the four variables I get to the different text boxes.</p>
  
  <pre><code>private void SetText(string text)
      {
          if (this.txtOutput.InvokeRequired)
          {
              SetTextCallback d = new SetTextCallback(SetText);
              this.BeginInvoke(d, new object[] { text });
          }
          else
          {
              txtOutput.AppendText(text + "\r\n");
              string a = "", b = "", c = "", d="";
              string invia = text.ToString();
              Stripper strp = new Stripper();
              strp.Distri(invia, out a, out b, out c, out d);
              if (a != "")
              {
                  textBox7.Text = a; //currentRes
              }
              if (b != "")
              {
                  textBox2.Text = b; //temperature
              }
  
              if (d != "" )
              {
               textBox3.Text = d; //motor current
              }
  
              if (c == "1\r") //motor RPM
              {
                  timer3.Start();
              }
          }
      }
  </code></pre>
  
  <p>The problem I am facing is that I get hundred of values "a", "b" and "d" per second and obviously the relevant text boxes are flickering. Moreover I would like to average the value for each variable taking 100 samples of each type before showing them in the relevant text box. This would avoid flickering and would give a more accurate reading.</p>
  
  <p>How can I average each of the variable "a", "b" and "d" to x samples without freezing the application which meanwhile has to provide control for other features?
  Samples code will be really appreciated.</p>