void workerCommands_DoWork(object sender, DoWorkEventArgs e) { while (true) { if (workerCommands.CancellationPending) { e.Cancel = true; return; } // if paused we will sleep for 5 seconds, and the try again // we will remove the pause if it was set more than 6 hours ago // the pause is initiated when banned from AniDB or manually by the user if (Paused) { try { if (workerCommands.CancellationPending) { e.Cancel = true; return; } //logger.Trace("Queue is paused: {0}", pauseTime.Value); TimeSpan ts = DateTime.Now - pauseTime.Value; if (ts.TotalHours >= 6) { Paused = false; } } catch { } Thread.Sleep(5000); continue; } //logger.Trace("Looking for next command request..."); CommandRequestRepository repCR = new CommandRequestRepository(); CommandRequest crdb = repCR.GetNextDBCommandRequestGeneral(); if (crdb == null) return; if (workerCommands.CancellationPending) { e.Cancel = true; return; } QueueCount = repCR.GetQueuedCommandCountGeneral(); //logger.Trace("{0} commands remaining in queue", QueueCount); //logger.Trace("Next command request: {0}", crdb.CommandID); ICommandRequest icr = CommandHelper.GetCommand(crdb); if (icr == null) { logger.Error("No implementation found for command: {0}-{1}", crdb.CommandType, crdb.CommandID); } else { QueueState = icr.PrettyDescription; if (workerCommands.CancellationPending) { e.Cancel = true; return; } logger.Trace("Processing command request: {0}", crdb.CommandID); icr.ProcessCommand(); } logger.Trace("Deleting command request: {0}", crdb.CommandID); repCR.Delete(crdb.CommandRequestID); QueueCount = repCR.GetQueuedCommandCountGeneral(); } }
void btnHasherClear_Click(object sender, RoutedEventArgs e) { try { this.Cursor = Cursors.Wait; JMMService.CmdProcessorHasher.Stop(); // wait until the queue stops while (JMMService.CmdProcessorHasher.ProcessingCommands) { Thread.Sleep(200); } Thread.Sleep(200); CommandRequestRepository repCR = new CommandRequestRepository(); foreach (CommandRequest cr in repCR.GetAllCommandRequestHasher()) repCR.Delete(cr.CommandRequestID); JMMService.CmdProcessorHasher.Init(); } catch (Exception ex) { Utils.ShowErrorMessage(ex.Message); } this.Cursor = Cursors.Arrow; }
public void ClearImagesQueue() { try { JMMService.CmdProcessorImages.Stop(); // wait until the queue stops while (JMMService.CmdProcessorImages.ProcessingCommands) { Thread.Sleep(200); } Thread.Sleep(200); CommandRequestRepository repCR = new CommandRequestRepository(); foreach (CommandRequest cr in repCR.GetAllCommandRequestImages()) repCR.Delete(cr.CommandRequestID); JMMService.CmdProcessorImages.Init(); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } }