I'm writing a music player using NAudio. Before I close the player, I would like to call some methods that stop the playback. How do I do this?
Asked
Active
Viewed 1.6k times
0
-
1WPF? Winforms? Something else? – Oded Dec 17 '11 at 19:43
-
1It should automatically stop playing when the process exits. If it does keep going then you have a threading problem in your code. Look at the Thread.IsBackground property for a quick fix. Debug + Break All to debug it. AppDomain.ProcessExit is an event you're asking about. – Hans Passant Dec 17 '11 at 19:52
-
possible duplicate of [Firing event on application close](http://stackoverflow.com/questions/679829/firing-event-on-application-close) – nawfal Jan 10 '14 at 08:56
2 Answers
11
WinForms
Subscribe to the Application.ApplicationExit
event and in the event handler do your shutdown code.
WPF
Subscribe to the Application.Exit
event and in the event handler do your shutdown code.

David Heffernan
- 601,492
- 42
- 1,072
- 1,490

Oded
- 489,969
- 99
- 883
- 1,009
0
I think that Form.closed
event would be good as well.
edit: only if you have one form

geniaz1
- 1,143
- 1
- 11
- 16
-
music players have only one form I guess and when I want to close it I simply close the window. – geniaz1 Dec 17 '11 at 19:58
-
1Bad assumption. What about configuration forms? About form? Don't assume. – Oded Dec 17 '11 at 20:00
-
In the programs that I wrote the user cannot switch to the main form so the other form will lose focus. – geniaz1 Dec 17 '11 at 20:07
-
-
Yes, just like that AboutDialog dlg = new AboutDialog(); dlg.ShowDialog(this); dlg.Dispose(); – geniaz1 Dec 17 '11 at 20:13
-
I mean, is the application the OP is asking about one of the applications you have written? If not, how can you assume you know how it was coded? – Oded Dec 17 '11 at 20:14