In .NET putem sa alegem din 3 tipuri de timer: System.Timer - thread timer; System.Thread.Timer - server base timer; System.Windows.Forms.Timer - windows base timer; System.Windows.Forms.Timer se foloseste in general pe UI, cand trebuie sa facem update. System.Timer o sa il folosim de obicei de obicei pe partea de server cand vrem mai multe flexibilitate si mai mult optiuni. Din cele trei timer-uri, acesta are cele mai multe optiuni. System.Thread.Timer, care rulează un nou thread pentru operațiile sale. Acesta este folositor când vrem sa facem operații asyncron. System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(ExecutaCeva), null, 0, 2000); ... private void ExecutaCeva(object obj) { .... } Pentru a face disable/enable putem sa folosim: timer.Change(Timeout.Infinite, Timeout.Infinite); //Disable. timer.Change(0, 2000); //Enable. Cea ce mi s-a parut foarte folositor la acest imer sunt parametrii lui Change si ultimii doi parametrii a contructorului. Prin i...
DREAMER, CRAFTER, TECHNOLOGY ENTHUSIAST, SPEAKER, TRAINER, AZURE MVP, SOLVING HARD BUSINESS PROBLEMS WITH CUTTING-EDGE TECHNOLOGY