title: Limiting CPU Usage in a Ticker Component in C# .NET 1.1
body: <p>I created a Ticker component (System.Windows.Forms.UserControl) in C# .NET 1.1 using System.Threading.Thread. This ticker will scroll from right to left and reading data from xml feed. This component will be invoked by our main application with videos, and other processes running. </p>
  
  <p>Testing the application without the ticker component consumes CPU maximum of 55%, however, when integrating the Ticker component it goes up as high as 95%.</p>
  
  <p>I also tried using the System.Windows.Forms.Timer but the result was the same.</p>
  
  <p>Parsing of Xml data occurs during initialization of the component only and here is the sample code snippet that will process the ticker to scroll:</p>
  
  <pre><code>Thread _mainThread;
  
  private void InitTickerThread() 
  {
  _panelHeadlines = (Panel) FindControl("panelHeadlines", this);
  
  if(_panelHeadlines != null) 
  {
      _textWidth = _panelHeadlines.Size.Width;
  }
  
  _locXOffset = 0;
  
  _mainThread = new Thread(new ThreadStart(StartScrolling));
  _mainThread.Name = "Main Ticker Thread";
  _mainThread.Priority = ThreadPriority.Lowest;
  _mainThread.IsBackground = true;
  _mainThread.Start();
  }
  
  private void StartScrolling() 
  {
  while(true) 
  {
      lock(this)
      {
          _locXOffset -= 1;
  
  
          if (_locXOffset &lt; -_textWidth) //If entire ticker content has finished scrolling.
          {
              _locXOffset = 0;
              _partnerCtr = 0;
  
              Partner p = _arrListPartners[_partnerCtr] as Partner;
              if(p != null) 
              {
                  pbPartnerLogo.Image = p.Logo;
                  _partnerContentWidth = p.ContentWidth - _offsetToChangeLogo;
              }
          } 
          else 
          {
              if(_locXOffset &lt; -_partnerContentWidth) 
              {
                  _partnerCtr++;
  
                  if(_arrListPartners.Count &gt; 0) 
                  {
                      if(_partnerCtr &lt; _arrListPartners.Count) 
                      {
                          Partner p = _arrListPartners[_partnerCtr] as Partner;
  
                          if(p != null) 
                          {
                              pbPartnerLogo.Image = p.Logo;
                              _partnerContentWidth = p.ContentWidth - _offsetToChangeLogo;
                          }
                      }
                  }
              }
          }
  
  
          _panelHeadlines.Location = new Point(_locXOffset, 0);
  
          Invalidate();
  
          Thread.Sleep(20);
      }
  }
  }
  </code></pre>
  
  <p>Any help is highly appreciated. Thanks!</p>