possible deadlock fix

This commit is contained in:
Master Kwoth 2016-01-31 20:24:06 +01:00
parent e869972127
commit e1d053abb1

View File

@ -26,16 +26,13 @@ namespace NadekoBot.Classes.Music {
public MusicControls() { public MusicControls() {
Task.Run(async () => { Task.Run(async () => {
while (!Stopped) { while (!Stopped) {
lock (_voiceLock) {
if (CurrentSong == null) { if (CurrentSong == null) {
if (SongQueue.Count > 0) if (SongQueue.Count > 0)
LoadNextSong().Wait(); await LoadNextSong();
} else if (CurrentSong.State == StreamState.Completed || NextSong) { } else if (CurrentSong.State == StreamState.Completed || NextSong) {
NextSong = false; NextSong = false;
LoadNextSong().Wait(); await LoadNextSong();
}
} }
await Task.Delay(1000); await Task.Delay(1000);
} }
@ -71,7 +68,6 @@ namespace NadekoBot.Classes.Music {
} }
internal void Stop() { internal void Stop() {
lock (_voiceLock) {
Stopped = true; Stopped = true;
foreach (var kvp in SongQueue) { foreach (var kvp in SongQueue) {
if (kvp != null) if (kvp != null)
@ -83,7 +79,6 @@ namespace NadekoBot.Classes.Music {
VoiceClient?.Disconnect(); VoiceClient?.Disconnect();
VoiceClient = null; VoiceClient = null;
} }
}
internal bool TogglePause() => IsPaused = !IsPaused; internal bool TogglePause() => IsPaused = !IsPaused;
} }