static void thQueueSend(object obj) { if (isTelegram) { return; } string msg; string rst = string.Empty; try { isTelegram = true; while (queTelegram.Count > 0) { try { TelegramQueData q = queTelegram.Dequeue(); SendMessage(q.Token, q.ChatId, q.Msg, out rst); dtmlastTelegramSend = DateTime.Now; System.Threading.Thread.Sleep(500); } catch { } } TimeSpan sp = DateTime.Now - dtmlastTelegramSend; //30분 이상 없을경우 if (sp.TotalMinutes >= 30 && _token_30min != null) { msg = "WebMonitoring 30min Check"; SendMessage(_token_30min, _chatid_30min, msg, out rst); dtmlastTelegramSend = DateTime.Now; } } catch { } finally { isTelegram = false; } }
/// <summary> /// 큐를 이용히여 텔레그램에 메시지를 보낸다. /// </summary> /// <param name="token"></param> /// <param name="chatid"></param> /// <param name="msg"></param> public static void QueTelegramSend(string token, string chatid, string msg) { try { TelegramQueData q = new TelegramQueData(token, chatid, msg); queTelegram.Enqueue(q); //첫 실행시 카카오 쓰레드 시작 if (tmrTelegram == null) { dtmlastTelegramSend = DateTime.Now; tmrTelegram = new System.Threading.Timer(new System.Threading.TimerCallback(thQueueSend), null, 0, 500); } } catch (Exception ex) { } }