Advertisement
Guest User

ejemplo mas o menos

a guest
Jun 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. public class startTimer
  2. {
  3.     Timer timer;
  4.     GameClient Session;
  5.     int timeLeft;
  6.  
  7.     public startTimer(GameClient Session, class Function)
  8.     {
  9.         this.Session = Session;
  10.  
  11.         int time = 1;
  12.         timeLeft = time * 500;
  13.  
  14.         startTimer();
  15.     }
  16.  
  17.     public void start()
  18.     {
  19.         TimerCallback timerFinished = timerDone;
  20.         timer = new Timer(timerFinished, null, 500, Timeout.Infinite);
  21.     }
  22.  
  23.     public void timerDone(object info)
  24.     {
  25.         try
  26.         {
  27.             timeLeft -= 500;
  28.  
  29.             #region Conditions
  30.             if (Session == null)
  31.             { stopTimer(); return; }
  32.  
  33.             if (timeLeft > 0)
  34.             {
  35.                 // aqui se pone la clase a ejecutar
  36.                 new Function();
  37.  
  38.                 timer.Change(500, Timeout.Infinite);
  39.                 return;
  40.             }
  41.         }
  42.         catch { stopTimer(); }
  43.     }
  44.  
  45.     public int getTime()
  46.     {
  47.         int minutesRemaining = timeLeft / 60000;
  48.         return minutesRemaining;
  49.     }
  50.  
  51.     public void stopTimer()
  52.     {
  53.         timer.Dispose();
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement