title: Thread loop, closing it in an Optimal way
body: <p>Okay well, here is the code:</p>
  
  <pre><code>    private void Receivev2()
      { 
          try
          {
              using (UdpClient udpclient = new UdpClient(1500))
              {
                  while (connect == true)
                  {
  
                      byte[] byteData = udpclient.Receive(ref remoteEP);
                      waveProvider.AddSamples(byteData, 0, byteData.Length);
                      if (Record == true)
                      {
                          waveWriter.Write(byteData, 0, byteData.Length);
                      }
  
                  }
              }
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message, "VoiceChat-Receive ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
      }
  </code></pre>
  
  <p>It´s on a Thread, and well, it receives data from udp and plays it, nothing weird.</p>
  
  <p>My problem however, is to make it stop normally, or well, don´t know how to put it.</p>
  
  <p>But let´s say, i start the thread and it loops.
  Then if i close my application, the application won´t "close", as the thread isn´t closing.</p>
  
  <p>Now to solve that, i use IsBackground = true.</p>
  
  <p>But i am not sure if that is an optimal way to do it, it feels like it will just force it to shut down, like ProcessKill or something.</p>
  
  <p>Maybe it is the correct way, i don´t know.</p>
  
  <p>Please give me advice on this.</p>