How to implement the OnExit method in my XNA game?

Is there any method for C # XNA games that determines if the user pressed the cross button to close the program, or pressed ALT + F4 to close ..?

The ALT + F4 keys can probably be found on KeyBoardState, but how can I detect the click of a cross button to close the window?

I need this so that I can turn off all threads running when the user closes the game by any means. I currently have some streams still running when the game closes, which makes the music still play: P

Note that this method must be compatible with Windows and the Xbox 360, as the game should work on both of these platforms (maybe Zune too).

+4
source share
1 answer

Either override the OnExiting method of the Game or sign its Exiting event.

Example:

 protected override void OnExiting(Object sender, EventArgs args) { base.OnExiting(sender, args); // Stop the threads } 
+8
source

All Articles