Q:

Averaging serial data stream values

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.
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();
            }
        }
    }

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.
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.

A:

average the value for each variable taking 100 samples ... would give a more accurate reading

So where does this number 100 come from, just from the GUI design or is it somehow related to the data?
And do you want to average independent (adjacent) blocks or do you need a moving average?
A simple approach: 
class Accum
{
    private int sum, count;

    public event AverageChanged; 

    public void Add(int value)
    {
       sum += value;
       count += 1;
       if (count >= 100)
       {
           OnAvarerageChanged(sum/count);
           sum = 0;
           count = 0;
       }
    }

    ....

}

You will need to create 3 instances of this on your form. Since all SerialPort data will happen on the same thread you'll only need to synchronize when handling the event.
Update:
The easiest but less general approach:
class Accum
{
    private int sum, count;

    //public event AverageChanged; 

    public void Add(int value)
    {
       sum += value;
       count += 1;
       if (count >= 100)
       {
           OnAvarerageChanged(sum/count);
           sum = 0;
           count = 0;
       }
    }

    public Label MyLabel { get; set; }

    private void OnAvarerageChanged(int av)
    {
        SetTextCallback d = new SetTextCallback(SetText);
        string text = av.ToString();
        MyLabel.BeginInvoke(d, new object[] { text });
    }

    private void SetText(string text)
    {
        this.MyLabel.Text = text;
    }

}

