Fix deadlock from Stop/HandleCommandAsync
This commit is contained in:
parent
fb26986a58
commit
317a495f46
|
@ -22,10 +22,15 @@ public class DiscordBot
|
||||||
{
|
{
|
||||||
CommandHandler.RegisterCommand("dscrestart", _ =>
|
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
|
#pragma warning disable CS4014
|
||||||
Init();
|
Init();
|
||||||
#pragma warning restore CS4014
|
#pragma warning restore CS4014
|
||||||
|
});
|
||||||
return "Restarting Discord bot...";
|
return "Restarting Discord bot...";
|
||||||
});
|
});
|
||||||
logger.Info("Starting discord bot (ctor)");
|
logger.Info("Starting discord bot (ctor)");
|
||||||
|
|
Loading…
Reference in New Issue