multithreading - How to run a function after a specific time -


i want if there way execute function after specific time in windows phone 7.? instance, see code in android:

mrunnable=new runnable()  {  @override public void run()   {  // work done } 

now function

public void otherfunction() { mhandler.postdelayed(mrunnable,15*1000); } 

now work done in upper code executed after 15 seconds of execution of otherfunction(). , want know possible in way in windows phone 7 also.? thanx in advance..

although can use reactive extensions if want, there's no need. can timer:

// @ class scope private system.threading.timer mytimer = null;   void somemethod() {     // creates one-shot timer fire after 15 seconds.     // last parameter (-1 milliseconds) means timer won't fire again.     // run method executed when timer fires.     mytimer = new timer(() =>         {             run();         }, null, timespan.fromseconds(15), timespan.frommilliseconds(-1)); } 

note run method executed on thread pool thread. if need modify ui, you'll have use dispatcher.

this method preferred on creating thread nothing wait. timer uses few system resources. when timer fires thread created. sleeping thread, on other hand, takes considerably more system resources.


Comments