I use MediaPlayer to play the background music. Sometimes, the music does not stop playing when I exit the game. This is even though I use the following code:

    protected override void OnExiting(Object sender, EventArgs args)
        base.OnExiting(sender, args);


What is wrong?

  • 1
    \$\begingroup\$ Welcome to GDSE. Have you noticed any pattern that seems to trigger the problem more or less often (how you exit the game, last action in the game, etc)? What happens if you call Stop() before onExiting(sender, args)? \$\endgroup\$
    – Pikalek
    Aug 13, 2019 at 15:49
  • \$\begingroup\$ I noticed it happens when I close the window when the opening (title) screen is shown. \$\endgroup\$
    – Adok
    Aug 14, 2019 at 10:23
  • \$\begingroup\$ Does this only appears on the title screen, and not in the rest of the game? In that case, you should look up the code of your title screen if you see something notable. \$\endgroup\$
    – Steven
    Aug 19, 2019 at 6:19

1 Answer 1


As suggested in the comments, you might need to put MediaPlayer.Stop(); before base.OnExiting(sender, args);.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .