Increased music stability

This commit is contained in:
Kwoth 2016-10-19 10:22:37 +02:00
parent 2014fc8885
commit a3bf2d5efb

View File

@ -92,8 +92,6 @@ namespace NadekoBot.Modules.Music.Classes
}).ConfigureAwait(false);
var t = new Thread(new ThreadStart(async () =>
{
try
{
while (!Destroyed)
{
@ -101,6 +99,8 @@ namespace NadekoBot.Modules.Music.Classes
{
if (audioClient?.ConnectionState != ConnectionState.Connected)
{
if (audioClient != null)
try { await audioClient.DisconnectAsync().ConfigureAwait(false); } catch { }
audioClient = await PlaybackVoiceChannel.ConnectAsync().ConfigureAwait(false);
continue;
}
@ -125,6 +125,11 @@ namespace NadekoBot.Modules.Music.Classes
}
catch (OperationCanceledException) { }
catch (Exception ex)
{
Console.WriteLine("Music thread almost crashed.");
Console.WriteLine(ex);
}
finally
{
if (!cancelToken.IsCancellationRequested)
@ -137,11 +142,6 @@ namespace NadekoBot.Modules.Music.Classes
await Task.Delay(300).ConfigureAwait(false);
}
}
}
catch (Exception ex) {
Console.WriteLine("Music thread crashed.");
Console.WriteLine(ex);
}
}));
t.Start();