private void DownloadUpdates() { try { var updates = _telegramMethods.GetUpdates(LastUpdateId + 1, null, null, AllowedUpdates).Result; if (updates.Count == 0) { return; } updates.ForEach(update => { Update = update; LastUpdateId = update.UpdateId; UpdatesArrivedEvent?.Invoke(this); }); } catch (TelegramMethodsException ex) { var message = "An error occurred while receiving the update"; UpdatesTracingStoppedEvent?.Invoke(this, new BotRequestErrorEventArgs(message, ex)); } finally { DownloadBotRequestsSemaphore.Release(); } }
private void RequestMonitorTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //если образовалась очередь, выдать ошибку задержки ответа сервера if (!DownloadBotRequestsSemaphore.WaitOne(0)) { var message = "Telegram server response timeout. Can't download content."; _requestMonitorTimer.Stop(); UpdatesTracingStoppedEvent?.Invoke(this, new BotRequestErrorEventArgs(message)); return; } DownloadUpdates(); }