Advertisement
Guest User

c#Timers

a guest
Mar 27th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1.      
  2.  
  3.         public static System.Timers.ElapsedEventHandler myDelegate;
  4.         private bool delInUse;
  5.         public System.Timers.Timer myTimer;
  6.  
  7.  
  8.  
  9.   public void setTimer(double Interval,string cb,string arg = "")
  10.         {
  11.             if (delInUse) { myTimer.Elapsed -= myDelegate; };
  12.             myTimer.Stop();
  13.             myDelegate = (s, e) => DisplayTimeEvent(s, e, cb, arg);
  14.             myTimer.Elapsed += myDelegate;
  15.             delInUse = true;
  16.             myTimer.Interval = Interval;  // 1000;
  17.             myTimer.Start();
  18.         }
  19.         public void DisplayTimeEvent(object source, System.Timers.ElapsedEventArgs e, string cb, string arg)
  20.         {
  21.             nPrint("Timer involked callback="+ cb);
  22.             delInUse = false;
  23.             myTimer.Elapsed -= myDelegate;
  24.             tryCallBack(cb, "('" + arg + "');");
  25.             myTimer.Stop();
  26.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement