コード例 #1
0
ファイル: Mantis.cs プロジェクト: nate-yocom/mantis
 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);
         }
     }
 }
コード例 #2
0
        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;
                    }
                }
            }));
        }
コード例 #3
0
        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;
                        }
                    }
                }
            }));
        }