public void WaitForFirstMessage() { pollingCollectionObserver = PollingCollectionObserver.Observe(() => { try { if (Interlocked.Exchange(ref sending, 1) == 1) { return; } if (pendingMessages.TryDequeue(out OutgoingMessage message)) { do { message.SendMessage(cancellationToken); } while (pendingMessages.TryDequeue(out message)); } sending = 0; communicationProtocol.LogVerbose("Sending cycle completed. Wait for next message."); } catch (Exception) { //do nothing as this is executed without owning task } }, pendingMessages); }
public void WaitForFirstMessage() { readingThread = new Thread(StartReading) { Priority = ThreadPriority.AboveNormal, IsBackground = true }; readingThread.Start(); pollingCollectionObserver = PollingCollectionObserver.Observe(Flush, messages); }
public void WaitForFirstMessage() { pollingCollectionObserver = PollingCollectionObserver.Observe(() => { try { if (Interlocked.Exchange(ref sending, 1) == 1) { return; } while (pendingConfirmations.TryDequeue(out Confirmation confirmation)) { confirmation.Send(); } if (resendMessages.TryDequeue(out OutgoingMessage resend)) { do { SendMessage(resend); } while (resendMessages.TryDequeue(out resend)); } else if (unconfirmedMessages.IsEmpty && pendingMessages.TryDequeue(out OutgoingMessage message)) { SendMessage(message); } sending = 0; log.LogVerbose("Sending cycle completed. Wait for next message."); } catch (Exception) { //do nothing as this is executed without owning task } }, pendingConfirmations, pendingMessages, resendMessages); void SendMessage(OutgoingMessage message) { unconfirmedMessages.TryAdd(message.Id, message); message.SendMessage(cancellationToken); } }