private async Task SendFromQueue() { while (!_waitSendConfirmation.IsEmpty) { var msgs = new HashSet <long>(); while (!_waitSendConfirmation.IsEmpty) { _waitSendConfirmation.TryDequeue(out var item); msgs.Add(item); } try { Log.Debug($"Sending confirmation for messages {string.Join(",", msgs.Select(m => m.ToString()))}"); var message = new TMsgsAck { MsgIds = new TVector <long>(msgs.ToArray()) }; await MtProtoSender.SendWithoutConfirm(message); } catch (Exception e) { Log.Error("Sending confirmation for messages failed", e); } } }
public void StartSendingConfirmation() { ThreadPool.QueueUserWorkItem( state => { while (true) { if (_waitSendConfirmation.IsEmpty) { _resetEvent.Reset(); _resetEvent.Wait(); } var msgs = new HashSet <long>(); while (!_waitSendConfirmation.IsEmpty) { _waitSendConfirmation.TryDequeue(out var item); msgs.Add(item); } try { Log.Debug($"Sending confirmation for messages {string.Join(",", msgs.Select(m => m.ToString()))}"); var message = new TMsgsAck() { MsgIds = new TVector <long>(msgs.ToArray()) }; MtProtoSender.Send(message); } catch (Exception e) { Log.Error("Process message failed", e); } } }); }