title: How to stop thread in C#?
body: <p>Info: I'm creating game using C# in Visual Studio 2017</p>
  
  <p>How can I stop music thread? Is it possible even from different form?
  I used this code to create thread which plays music in background</p>
  
  <pre><code>MediaPlayer bg;
  
  public void main()
  {
      IntializeComponent();
      Bg_music();
  }
  
  private void Bg_music()
  {
      new System.Threading.Thread(() =&gt;
      {
          bg = new System.Windows.Media.MediaPlayer();
          bg.Open(new System.Uri(path + "Foniqz_-_Spectrum_Subdiffusion_Mix_real.wav"));
          bg.Play();
      }).Start();                        
  }
  </code></pre>
  
  <p>When I try to stop the thread using this code, it stops window which is currently open and music/thread keeps playing music</p>
  
  <pre><code>bg.Dispatcher.Invoke(() =&gt;
  {
      bg.Close();
  });
  </code></pre>
  
  <p>also this didn't work</p>
  
  <pre><code>bg.Dispatcher.Invoke(() =&gt;
  {
      bg.Stop();
  });
  </code></pre>