public static void Discover(int pingCount, int delayBetweenMilliseconds) { for (int x = 0; x < pingCount; x++) { Debug("Discover ping send {0}/{1}", x, pingCount); NetworkPump.Send(ControlMessage.CreateBroadcastControlMessage(ControlMessageId.Ping)); if (delayBetweenMilliseconds > 0) { System.Threading.Thread.Sleep(delayBetweenMilliseconds); } } }
private Task SendAndValidate(ControlMessage messageToSend, Func <bool> validateFunc, int timeoutInSeconds) { DateTime timeoutAt = DateTime.Now + TimeSpan.FromSeconds(timeoutInSeconds); long firstSendAt = m_stopwatch.ElapsedTicks; return(Task.Run(() => { while (timeoutInSeconds == -1 || DateTime.Now < timeoutAt) { NetworkPump.Send(messageToSend); System.Threading.Thread.Sleep(1000); if (validateFunc()) { break; } } })); }
private Task SendAndExpect(ControlMessage messageToSend, BreweryMessageType responseExpected, int timeoutInSeconds) { DateTime timeoutAt = DateTime.Now + TimeSpan.FromSeconds(timeoutInSeconds); long firstSendAt = m_stopwatch.ElapsedTicks; return(Task.Run(() => { while (timeoutInSeconds == -1 || DateTime.Now < timeoutAt) { NetworkPump.Send(messageToSend); System.Threading.Thread.Sleep(1000); long ts = 0; if (m_receiptStamps.TryGetValue(responseExpected, out ts)) { if (ts >= firstSendAt) { break; } } } })); }