c# - How to repeat it at every X intervals? -


on property checking dns lookup executed @ startup only..how execute @ every x intervals

 system.net.iphostentry iphe = system.net.dns.gethostbyname("www.google.com");  return (@"images/online.png"); 

i'm making lot of assumptions here, assume talking keeping wpf form updated "online" status has auto-refresh feature? , doing in mvvm model.

if assumptions right, in view model can use system.timers.timer fire @ interval specify, , can execute method specify hooking elapsed event.

public class viewmodel{      private static system.timers.timer atimer;      public viewmodel()     {         atimer = new timer();         atimer.interval = 2000; // every 2 seconds          // hookup elapsed event         atimer.elapsed += dowork;          // have timer fire repeated events (true default)         atimer.autoreset = true;          // start timer         atimer.enabled = true;     }      public void dowork(object source, system.timers.elapsedeventargs e) {          //do work here     } } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -