c# - Setting up an elapsed timer event -
i need measure time difference between when last packet received , new 1 has arrived. have tried using timer class in c# 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 had event called if timer elapsed after length of time of interval. realised timer wait length of interval , call event. need figure out is, can work out difference of when packet came last , when new 1 has arrived. if can need evaluate against interval value , if greater call method work.
my brain has died trying figure out appreciated.
you should store datetime.now
, compare against stored value.
for example:
var lasttime = datetime.now; //do things... if ((datetime.now - lasttime).totalseconds > 5) //do other things
Comments
Post a Comment