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