c# - System.Timer not available in Metro Apps? What can I use instead of it? -


i trying poll server , json @ regular intervals reason cannot see reference system.timers in blank app writing. code

public mainwindow() {     timer.tick += new eventhandler(checkjson_click_1);     timer.interval = 30000; //30sec*1000microsec                  timer.enabled = true;                            timer.start(); }  private async void checkjson_click_1(object sender, routedeventargs e) {     var client = new httpclient();     client.maxresponsecontentbuffersize = 1024 * 1024;            var response = await client.getasync(new uri("uri"));     var result = await response.content.readasstringasync();           var component = jsonobject.parse(result);      } 

can let me know can use instead of timer?

system.timers.timer set raise events on threadpool threads. if you're using now, you'll want use new threadpooltimer class.

if want raise events on ui thread instead, you'll want new dispatchertimer, replacement system.windows.forms.timer.

edit: comments indicate want use dispatchertimer, you're having trouble code. here's straight translation of you've got in comments:

public void starttimer(object o, routedeventargs sender) {      this.timer = new dispatchertimer();      // easier way specify timespan durations     timer.interval = timespan.frommilliseconds(100);      // don't need delegate wrapper     timer.tick += checkjson_tick;      timer.start(); }  void checkjson_tick(object sender, eventargs e) {     // ... } 

Comments