c# - How To Periodically Execute A Function -


how can execute c# method every 40 seconds continuously?

you should use timer functionality available in .net

documentation

here's code msdn, slight changes.

public class timer1 {     private static system.timers.timer atimer;      public static void main()     {          // create timer fourty second interval.         atimer = new system.timers.timer(40000);          // hook elapsed event timer.         atimer.elapsed += new elapsedeventhandler(ontimedevent);               // if timer declared in long-running method, use          // keepalive prevent garbage collection occurring          // before method ends.          //gc.keepalive(atimer);     }      // specify want happen when elapsed event       // raised.      private static void ontimedevent(object source, elapsedeventargs e)     {         //code needs repeating every fourty seconds     } } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -