public BackgroundThreadManager( IDiscordThread discordThread, IDatabaseThread databaseThread) { _discordThread = discordThread; _dbThread = databaseThread; _discordWorker = new BackgroundWorker(); _discordWorker.DoWork += ProcessDiscordThread; _discordWorker.WorkerSupportsCancellation = true; _dbWorker = new BackgroundWorker(); _dbWorker.DoWork += ProcessDatabaseThread; _dbWorker.WorkerSupportsCancellation = true; AppDomain.CurrentDomain.ProcessExit += CurrentDomainOnProcessExit; }
public BackgroundThreadManager( IDatabaseThread databaseThread) { // Temporarily double thread limit to try to get us running for longer than 8 hours. // Not a long-term solution, but we'll see if it works in the meantime. const int MaxThreads = 250; bool success = ThreadPool.SetMaxThreads(MaxThreads, MaxThreads); if (!success) { throw new Exception("Failed to set max threads to " + MaxThreads + "."); } _dbThread = databaseThread; _dbWorker = new Thread(x => ProcessDatabaseThread()); _dbWorker.IsBackground = true; _isShuttingDown = false; AppDomain.CurrentDomain.ProcessExit += CurrentDomainOnProcessExit; }