Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In this case it's better to use two <a href="http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx" rel="nofollow"><code>System.Threading.Timer</code></a> and execute your cpu-intensive operations in these two threads. Please note that you <strong>must</strong> access controls with <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.begininvoke.aspx" rel="nofollow"><code>BeginInvoke</code></a>. You can encapsulate those accesses into properties setter or even better pull them out to a view model class.</p> <pre><code>public class MyForm : Form { private System.Threading.Timer gpuUpdateTimer; private System.Threading.Timer cpuUpdateTimer; protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!DesignMode) { gpuUpdateTimer = new System.Threading.Timer(UpdateGpuView, null, 0, 1000); cpuUpdateTimer = new System.Threading.Timer(UpdateCpuView, null, 0, 100); } } private string GpuText { set { if (InvokeRequired) { BeginInvoke(new Action(() =&gt; gpuLabel.Text = value), null); } } } private string TemperatureLabel { set { if (InvokeRequired) { BeginInvoke(new Action(() =&gt; temperatureLabel.Text = value), null); } } } private void UpdateCpuView(object state) { // do your stuff here // // do not access control directly, use BeginInvoke! TemperatureLabel = sensor.Value.ToString() + "c" // whatever } private void UpdateGpuView(object state) { // do your stuff here // // do not access control directly, use BeginInvoke! GpuText = sensor.Value.ToString() + "c"; // whatever } protected override void Dispose(bool disposing) { if (disposing) { if (cpuTimer != null) { cpuTimer.Dispose(); } if (gpuTimer != null) { gpuTimer.Dispose(); } } base.Dispose(disposing); } </code></pre>
 

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