Note that there are some explanatory texts on larger screens.

plurals
  1. POMultithreading or something different
    primarykey
    data
    text
    <p>This is the first time I face a problem like this. Not being this my profession but only my hobby, I have no previous references. In my program I have added one by one several functions to control a machine. After I added the last function (temperature measurement), I have started experiencing problems on other functions (approx. 8 of them running all together. The problem I am experiencing is on a chart (RPM of a motor) that is not related to this function but is affected by it. You see the difference between these two charts with and without the temperature measurement running. The real speed of the motor is the same in both charts but in the second one I loose pieces on the fly because the application slows down.</p> <p>Without the temperature function. <img src="https://i.stack.imgur.com/QjTGI.jpg" alt="enter image description here"> With the temperature function <img src="https://i.stack.imgur.com/eajVF.jpg" alt="enter image description here"></p> <p>Particularly this function is disturbing the above control and I think is because the work load is becoming heavy for the application and or because I need sampling so there is some time waiting to get them:</p> <pre><code>private void AddT(decimal valueTemp) { sumTemp += valueTemp; countTemp += 1; if (countTemp &gt;= 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 &gt; 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; } } </code></pre> <p>I am wondering if running this function on a different thread would solve the problem and how I can do that? Or if there is a different way to solve the problem.Sample code will be appreciated.</p> <p><strong>Update, added method call.</strong></p> <p>This is how I call the method AddT</p> <pre><code>if (b != "") { decimal convTemp; //corrente resistenza decimal.TryParse(b, out convTemp); AddT(convTemp);} </code></pre> <p><a href="http://pastebin.com/5aAhAJ2A" rel="nofollow noreferrer">This</a> is how I receive the data from the serial and pass it to the class that strips out unwonted chars and return values to the different variables. <a href="http://pastebin.com/yjyXQCCr" rel="nofollow noreferrer">This</a> is the class that strips out the unwonted chars and return the values. And <a href="http://pastebin.com/3mVzEaFD" rel="nofollow noreferrer">this</a> is how I manage the serial incoming data. Please do not laugh at me after seeing my coding. I do a different job and I am learning on my own. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload