Hi, I need to measure the time difference between when the last packet was received and the new one has arrived. I have tried using the Timer class in C# as such:
while (listening)
{
if (hB != null)
{
interval = hB.GetHBInterval();
aTimer = new System.Timers.Timer(interval+5);
Console.WriteLine("Interval is: {0}", interval);
byte[] bytes = listener.Receive(ref groupEP);
DecodeUDPMessage(Encoding.UTF8.GetString(bytes, 0, bytes.Length));
}
else
{
byte[] bytes = listener.Receive(ref groupEP);
DecodeUDPMessage(Encoding.UTF8.GetString(bytes, 0, bytes.Length));
}
}
I originally had it so that an event would be called if the timer elapsed after the length of time of the interval. But realised that the timer will wait for the length of the interval and then call the event. What I need to figure out is, can I work out the difference of when a packet came last and when the new one has arrived. If I can then I need to evaluate it against the interval value and if it is greater then call another method that will do some work.
My brain has died trying to figure this out so any help would be greatly appreciated.