Info: I'm creating game using C# in Visual Studio 2017
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
MediaPlayer bg;
public void main()
{
IntializeComponent();
Bg_music();
}
private void Bg_music()
{
new System.Threading.Thread(() =>
{
bg = new System.Windows.Media.MediaPlayer();
bg.Open(new System.Uri(path + "Foniqz_-_Spectrum_Subdiffusion_Mix_real.wav"));
bg.Play();
}).Start();
}
When I try to stop the thread using this code, it stops window which is currently open and music/thread keeps playing music
bg.Dispatcher.Invoke(() =>
{
bg.Close();
});
also this didn't work
bg.Dispatcher.Invoke(() =>
{
bg.Stop();
});