title: Trying to make a try catch continuously loop until service resumes
body: <p>I basically have a method that is checking a service constantly in a different thread. This works fine, but I need to make a check so that if the host closes, it keeps trying until service is resumed.</p>
  
  <p>I thought this would work</p>
  
  <pre><code>private void GetTankLevels()
          {
              Service1Client client = new Service1Client();
              while (true)
              {
                  try
                  {
                      this.DieselBox.Invoke(new MethodInvoker(delegate { DieselBox.Text = client.GetTankAmounts("Diesel").ToString(); }));
                      this.PetrolBox.Invoke(new MethodInvoker(delegate { PetrolBox.Text = client.GetTankAmounts("Unleaded").ToString(); }));
                      double DFuelLvl = client.GetTankAmounts("Diesel");
                      double PFuelLvl = client.GetTankAmounts("Unleaded");
  
                      int DieselProgress = (int)DFuelLvl;
                      int petrolProgress = (int)PFuelLvl;
                      if (DFuelLvl &lt; 300)
                      {
  
                          this.DieselBar.Invoke(new MethodInvoker(delegate { DieselBar.Value = DieselProgress; }));
  
                      }
                      else if (DFuelLvl &gt; 300 &amp;&amp; DFuelLvl &lt; 500)
                      {
                          this.DieselBar.Invoke(new MethodInvoker(delegate { DieselBar.Value = DieselProgress; }));
  
                      }
                      else if (DFuelLvl &gt; 500 &amp;&amp; DFuelLvl &lt; 850)
                      {
                          this.DieselBar.Invoke(new MethodInvoker(delegate { DieselBar.Value = DieselProgress; }));
  
                      }
                      else
                      {
                          this.DieselBar.Invoke(new MethodInvoker(delegate { DieselBar.Value = DieselProgress; }));
  
                      }
  
                      if (PFuelLvl &lt; 300)
                      {
                          this.Petrolbar.Invoke(new MethodInvoker(delegate { Petrolbar.Value = petrolProgress; }));
  
                      }
                      else if (PFuelLvl &gt; 300 &amp;&amp; PFuelLvl &lt; 500)
                      {
                          this.Petrolbar.Invoke(new MethodInvoker(delegate { Petrolbar.Value = petrolProgress; }));
  
                      }
                      else if (PFuelLvl &gt; 500 &amp;&amp; PFuelLvl &lt; 850)
                      {
                          this.Petrolbar.Invoke(new MethodInvoker(delegate { Petrolbar.Value = petrolProgress; }));
  
                      }
                      else
                      {
                          this.Petrolbar.Invoke(new MethodInvoker(delegate { Petrolbar.Value = petrolProgress; }));
  
                      }
                  }
                  catch
                  {
                      MessageBox.Show("Lost connection to the host... Please wait");
  
                  }
  
              }
          }
  </code></pre>
  
  <p>But it's being a bit unpredictable.
  Ideas?</p>