private static void DoWork(object data) { CrawlerThread crawler = (CrawlerThread)data; Downloader downloader = crawler.m_downloader; IQueueManager queue = downloader.UrlsQueueFrontier; while (true) { crawler.m_suspendEvent.WaitOne(Timeout.Infinite); if (queue.Count > 0) { try { // 从队列中获取URL string url = (string)queue.Dequeue(); // 获取页面 Fetch(crawler, url); // TODO: 检测是否完成 //if (false) break; } catch (InvalidOperationException) { SleepWhenQueueIsEmpty(crawler); } } else { SleepWhenQueueIsEmpty(crawler); } } }
public CommandResult Process() { if (_rovers.Any(x => x.State.Status == Status.Moving)) { return new CommandResult { ErrorMessage = "A rover is moving" } } ; var queue = _queueManager.Dequeue(); if (queue == null) { return(null); } var result = !_rovers.Any(x => x.Name == queue.RoverName) ? new CommandResult { ErrorMessage = $"No rover connected called as {queue.RoverName}" } : _rovers.First(x => x.Name == queue.RoverName).ApplyCommands(queue.Commands); if (result.Rover.State.Status == Status.Died) { DangerZoneDbRepo.Instance.Value.Add(result.Rover.State.X, result.Rover.State.Y); result.ErrorMessage = $"RIP {result.Rover.Name}"; } return(result); } }
public virtual void Launch(object evnt) { try { _threadNumber = ++_threadCount; ManualResetEvent doneEvent = (ManualResetEvent)evnt; while (true && !_cancelled) { doneEvent.WaitOne(); ByteBlock _block = _queueReader.Dequeue(); if (_block == null) { doneEvent.Set(); return; } using (MemoryStream _memoryStream = new MemoryStream()) { using (GZipStream cs = new GZipStream(_memoryStream, CompressionMode.Compress)) { cs.Write(_block.Buffer, 0, _block.Buffer.Length); } byte[] compressedData = _memoryStream.ToArray(); ByteBlock _out = new ByteBlock(_block.ID, compressedData); _queueWriter.EnqueueForWriting(_out); } } } catch (Exception ex) { Console.WriteLine("Ошибка в потоке {0}. \n Описание ошибки: {1}", _threadNumber, ex.Message); _cancelled = true; } }
public void PlayNextTrack() { logger.Debug("Dequeuing next track"); var nextToPlay = queueManager.Dequeue(); if (nextToPlay == null) { logger.Debug("Asking AutoPlay for next track"); nextToPlay = autoplayer.FindTrack(); if (nextToPlay != null) { logger.Debug("Track {0} found by autoplay", nextToPlay.ToLoggerFriendlyTrackName()); } } callbackClient.QueueChanged(queueManager.GetAll()); if (nextToPlay != null) { musicPlayer.PlayTrack(nextToPlay); } }