コード例 #1
0
 /// <summary>
 /// Checks if this Discord bot is the only instance of the application currently running.
 /// </summary>
 /// <returns>True if no other Discord bot with the same token is running.</returns>
 public bool SingleInstanceCheck()
 {
     if (allowMultipleInstances)
     {
         return(true);
     }
     if (mutex == null)
     {
         mutex = new Mutex(true, discordBot.GetDiscordToken(), out mutexCreatedNew);
     }
     if (!mutexCreatedNew)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine($"Startup Error: More than one instance of the Discord bot with this token is running!");
         Console.Beep();
         Console.Beep();
         Console.WriteLine("Press any key to exit...");
         Console.ResetColor();
         Console.ReadLine();
     }
     return(mutexCreatedNew);
 }