This is the first time I encounter such a problem. Not being my profession, but only my hobby, I have no previous links. In my program, I added one at a time several functions to control the machine. After I added the last function (temperature measurement), I began to experience problems with other functions (about 8 of them work together. The problem I am experiencing is a diagram (engine RPM), which is not related to it but to it you see the difference between the two diagrams with and without temperature measurement.The real engine speed is the same in both diagrams, and in the second I lose pieces on the fly because the application slows down.
No temperature function.
With temperature function 
In particular, this function interferes with the above management, and I think this is because the workload becomes heavy for the application and or because I need a selection, so there is some time waiting for them to be received:
private void AddT(decimal valueTemp) { sumTemp += valueTemp; countTemp += 1; if (countTemp >= 20) //take 20 samples and make average { OnAvarerageChangedTemp(sumTemp / countTemp); sumTemp = 0; countTemp = 0; } } private void OnAvarerageChangedTemp(decimal avTemp) { float val3 = (float)avTemp; decimal alarm = avTemp; textBox2.Text = avTemp.ToString("F"); if (alarm > 230) { System.Media.SoundPlayer player = new System.Media.SoundPlayer(); player.Stream = Properties.Resources.alarma; player.Play(); timer4.Start(); } else { timer4.Stop(); panel2.BackColor = SystemColors.Control; } }
I am wondering if this function allowed another thread to solve the problem and how can I do this? Or, if there is another way to solve the problem. Rate the code.
Update, add a method call.
So I call the AddT method
if (b != "") { decimal convTemp;
This is how I get data from the serial number and pass it to a class that removes unnecessary characters and returns values ββto other variables. This is a class that removes unnecessary characters and returns values. And this is how I manage sequential incoming data. Please do not laugh at me after seeing my coding. I do other work, and I study myself.
source share