title: Timer v/s thread.sleep in terms of cpu usage
body: <p>I am using DMX 512 conroller to send hex data to 3 serial ports with <code>while (true)</code> loop where I use multiple <code>Thread.Sleep(50)</code> multiple times which reduces CPU usage and gets stop working after few hours.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public static GO () 
  {
      try
      {
          dmx = new Dmx(2, 0);
  
          Thread mTh1 = new Thread(() =&gt; dmx.Start(RGBdata1, RGBdata2, RGBdata3)); 
  
          Global.tmrStarted = true;  // test it,ok
  
          mTh1.Start();
      }
  }
  </code></pre>
  
  <p>This is my start method where I send data to 3 ports where I used the <code>Thread.Sleep()</code> method multiple times:</p>
  
  <pre><code>while (Global.tmrStarted)
  {
      Break();
      Thread.Sleep(500); 
      if (m_port == null || m_port.IsOpen == false) return;
      m_port.Write(new byte[] { 0 }, 0, 1);
      SendData();
  
  
      Break1();
      Thread.Sleep(500); //uncommect this is you need, test
      if (m_port1 == null || m_port1.IsOpen == false) return;
      m_port1.Write(new byte[] { 0 }, 0, 1);
      SendData1();
      Break2();
      Thread.Sleep(500); //uncommect this is you need, test
  
      if (m_port4 == null || m_port4.IsOpen == false) return;
      m_port4.Write(new byte[] { 0 }, 0, 1);
      SendData2();
  
      Thread.Sleep(100);
  }
  </code></pre>
  
  <p>Can anyone suggest me how can I make above program thread-safe or using timer?</p>
  
  <p>Thanks in advance.</p>