private void DistributeLoop() { while (!isStopping) { var sb = new StringBuilder(); try { lockerQuotes.AcquireReaderLock(lockTimeout); } catch (ApplicationException) { continue; } try { foreach (var pair in quotes) { if (!pair.Value.IsComplete || pair.Value.isUpdated == false) { continue; } sb.AppendFormat("{0},{1},{2};", pair.Key, pair.Value.Bid.Value.ToStringUniform(), pair.Value.Ask.Value.ToStringUniform()); pair.Value.isUpdated = false; } } finally { lockerQuotes.ReleaseReaderLock(); } if (sb.Length > 0) { var quoteStr = sb.ToString(); logNoFlood.LogMessageFormatCheckFlood(LogEntryType.Info, LogMsgQuotesDistributed, 1000 * 60 * 60, "Раздаются котировки: " + quoteStr); //Logger.InfoFormat("QuoteDistributor: distributing {0} bytes quotes", sb.Length); tcpDistributor.DistributeStringData(quoteStr); } Thread.Sleep(minDistributeIntervalMil); } }
private void PollRoutine() { while (!isStopping) { Thread.Sleep(PollInterval); // запрашиваем новости bool timeoutFlag; var news = newsQueue.ExtractAll(Timeout, out timeoutFlag); if (timeoutFlag) { Logger.DebugFormat("Таймаут {0} при попытке получить новости на раздачу", Timeout); } if (news == null || timeoutFlag) { continue; } if (news.Count > 0) { //Logger.InfoFormat("Доставка online {0} котировок", news.Count); distributor.DistributeStringData(BaseNewsParser.ToString(news)); } } }