refactor: use using for SoundPlayer

This commit is contained in:
Anna 2020-08-03 23:16:07 -04:00
parent 0b54dc4271
commit 172bfa6025
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0

View File

@ -464,14 +464,14 @@ namespace PeepingTom {
} else {
player = new SoundPlayer(this.config.SoundPath);
}
try {
player.Play();
} catch (FileNotFoundException e) {
this.SendError($"Could not play sound: {e.Message}");
} catch (InvalidOperationException e) {
this.SendError($"Could not play sound: {e.Message}");
} finally {
player.Dispose();
using (player) {
try {
player.Play();
} catch (FileNotFoundException e) {
this.SendError($"Could not play sound: {e.Message}");
} catch (InvalidOperationException e) {
this.SendError($"Could not play sound: {e.Message}");
}
}
}