Fix deadlock from Stop/HandleCommandAsync

This commit is contained in:
TheUbMunster 2022-12-24 10:50:19 -07:00
parent fb26986a58
commit 317a495f46
1 changed files with 7 additions and 2 deletions

View File

@ -22,10 +22,15 @@ public class DiscordBot
{
CommandHandler.RegisterCommand("dscrestart", _ =>
{
Stop();
//Task.Run is to fix deadlock (dispose can only be finalized if all discord callbacks are returned,
//and since this delegate is called directly from a callback, it would cause a deadlock).
Task.Run(() =>
{
Stop();
#pragma warning disable CS4014
Init();
Init();
#pragma warning restore CS4014
});
return "Restarting Discord bot...";
});
logger.Info("Starting discord bot (ctor)");