title: How to run an infinite thread?
body: <p>I'm trying to run a Thread infinitely, but it's not working ...</p>
  
  <p>Follow the code:</p>
  
  <pre><code>namespace BTCPrice
  {
      public static class Price
      {
          private static volatile bool _shouldStop = false;
  
          public static void RequestStop()
          {
              _shouldStop = true;
          }
  
          public static void Refresh(out string value, int tipo = 0, string source = "https://www.mercadobitcoin.net/api/")
          {
              while (_shouldStop == false)
              {
  
                  JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
  
                  WebClient cliente = new WebClient();
  
                  string json = cliente.DownloadString(string.Format("{0}/{1}/{2}", source, "BTC", "ticker"));
  
                  JObject j = JObject.Parse(json);
  
                  switch (tipo)
                  {
                      //Get High Price
                      case 0:
                          value = j["ticker"]["high"].ToString();
                          break;
  
                      //Get Low Price
                      case 1:
                          value = j["ticker"]["low"].ToString();
                          break;
  
                      default:
                          value = "default";
                          break;
  
                  }
  
                  Thread.Sleep(1000);
              }
  
              value = "Stopped";
          }
      }
  }
  </code></pre>
  
  <p>On Start:</p>
  
  <pre><code>string result = "";
  Thread workerThread = new Thread(() =&gt; {
      Price.Refresh(out result);
  
      MessageBox.Show(result);
  
      Invoke(textBox1, result);
  
      Thread.Sleep(1000);
  });
  </code></pre>
  
  <p>No exception occurs ... as long as I remove the <code>While (_shouldStop == false)</code> class the code works perfectly. However, I would like that, while the program is open, it executes the code and updates the textbox with the value that I get by the API.</p>
  
  <p>result without While(_shouldStop == false) in class:</p>
  
  <p><a href="https://i.stack.imgur.com/Tt109.png" rel="nofollow noreferrer">Expected Result with While</a></p>