示例#1
0
    public static void SetTimer(float timerDuration, GameObject parent, TimerDelegate handler)
    {
        Timer t = parent.AddComponent <Timer>();

        t.targetTime = Time.time + timerDuration;
        t.handler    = handler;
    }
示例#2
0
文件: Timer.cs 项目: RobinJS/dotNET
 static void Main()
 {
     int t = 500;
     int duration = 5;
     TimerDelegate timer = new TimerDelegate(OnTimedEvent);
     timer(t, duration);
 }
示例#3
0
        /// <summary>
        /// 添加任务 指定延迟时间
        /// </summary>
        /// <param name="delayTime">秒</param>
        /// <param name="timeDelegate"></param>
        public void AddTimeEvent(long delayTime, TimerDelegate timeDelegate)
        {
            delayTime = delayTime / 1000;
            TimerModel model = new TimerModel(id.Add_Get(), DateTime.Now.Ticks + delayTime, timeDelegate);

            idModelDict.TryAdd(model.Id, model);
        }
示例#4
0
 public CustomTimer(TimerDelegate timerEvent, int interval)
 {
     this.Interval      = interval;
     this.timerDelegate = timerEvent;
     this.runTimer      = true;
     this.timerThread   = new Thread(new ThreadStart(this.StartTimer));
 }
 public TimerClass(TimerDelegate timerEvent, int interval)
 {
     this.Interval = interval;
     this.timerDelegate = timerEvent;
     this.runTimer = true;
     this.timerThread = new Thread(new ThreadStart(this.StartTimer));
 }
 static void Main()
 {
     TimerDelegate testMethod = new TimerDelegate(TestMethod);
     Timer timerTest = new Timer(testMethod, 4000);
     timerTest.Start();
     timerTest.End();
 }
示例#7
0
 void _Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     try
     {
         _Timer.Stop();
         if (!Dispatcher.CheckAccess())
         {
             TimerDelegate d = _Timer_Elapsed;
             Dispatcher.Invoke(d, sender, e);
         }
         else
         {
             if (PNStatic.HideSplash)
             {
                 _StartTimer = false;
                 Close();
             }
         }
     }
     catch (ThreadAbortException)
     {
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex, false);
     }
     finally
     {
         if (_StartTimer)
         {
             _Timer.Start();
         }
     }
 }
示例#8
0
		protected uint CreateTimer(uint delay, bool repeat, TimerDelegate callback, object cookie)
		{
			if (delay > 432000000u)
			{
				throw new Exception(string.Format("Timer delay {0} exceeds maximum {1}", delay, 432000000u));
			}
			if (delay == 0u)
			{
				delay = 1u;
			}
			if (callback == null)
			{
				throw new Exception("Null timer callback not supported nor useful");
			}
			uint next = TimerId.GetNext(ref this.idLast);
			Timer timer = new Timer(next, delay, repeat, callback, cookie, this.timeNow);
			uint num = this.timeNow + delay;
			if (num == this.lastTimeFire)
			{
				this.dynamicArray.Insert(++this.lastIndex, timer);
			}
			else
			{
				this.lastTimeFire = num;
				this.lastIndex = this.Add(timer);
			}
			if (this.lastIndex == 0)
			{
				this.timeNext = num;
			}
			return next;
		}
 public void ClearTimer(TimerDelegate timerDelegate)
 {
     if (m_timerModule != null)
     {
         m_timerModule.ClearTimer(timerDelegate);
     }
 }
示例#10
0
 private static void Main()
 {
     Console.Write("Enter timer period in seconds: ");
     int period = int.Parse(Console.ReadLine());
     var timerDelegate = new TimerDelegate(Timer.Start);
     timerDelegate(period);
 }
示例#11
0
 private static void Main()
 {
     Console.WriteLine("Press any key to stop:\n");
     CustomTimer timer = new CustomTimer();
     TimerDelegate d = new TimerDelegate(timer.StartTimer);
     d(1);
     Console.ReadKey();
 }
示例#12
0
 public SingleTimer(float Interval, TimerDelegate Event, bool IsLoop = false, bool DoExecuteImmediately = false, params object[] Params)
 {
     this.Interval             = Interval;
     this.Event                = Event;
     this.IsLoop               = IsLoop;
     this.DoExecuteImmediately = DoExecuteImmediately;
     this.Params               = Params;
 }
示例#13
0
文件: Timer.cs 项目: RobinJS/dotNET
        static void Main()
        {
            int           t        = 500;
            int           duration = 5;
            TimerDelegate timer    = new TimerDelegate(OnTimedEvent);

            timer(t, duration);
        }
示例#14
0
        static void Main(string[] args)
        {
            TimerDelegate d = null;

            d = d + Print;

            RepeatSomeMethod(d, 1, 10);
        }
示例#15
0
 public Wait(float duration, TimerDelegate dlg, BehaviorTreeNode child)
 {
     _children = new List <BehaviorTreeNode>(1);
     _children.Add(child);
     _waitTime = duration;
     _count    = 0;
     _timerDlg = dlg;
 }
示例#16
0
        public static void Main()
        {
            TimerDelegate timerDelegate = new TimerDelegate(Print);

            Timer timer = new Timer(ticksCount, interval, timerDelegate);
            Thread separateProcess = new Thread(new ThreadStart(timer.Run));
            separateProcess.Start();
        }
示例#17
0
        private static void Main()
        {
            Console.Write("Enter timer period in seconds: ");
            int period        = int.Parse(Console.ReadLine());
            var timerDelegate = new TimerDelegate(Timer.Start);

            timerDelegate(period);
        }
示例#18
0
 public uint CreateViewTimer(float delay, bool repeat, TimerDelegate callback, object cookie)
 {
     delay *= 1000f;
     if (delay < 0f || delay >= 4.2949673E+09f)
     {
         throw new Exception(string.Format("Timer delay {0} is out of range.  Check against TimerManager.MAX_DELAY_SECONDS", delay));
     }
     return(base.CreateTimer((uint)delay, repeat, callback, cookie));
 }
示例#19
0
        static void Main()
        {
            TimerDelegate timerElapsedDelegate = new TimerDelegate(PrintMessage);

            Timer testTimer = new Timer(5, 2000, timerElapsedDelegate);

            Thread thread = new Thread(new ThreadStart(testTimer.Run));
            thread.Start();
        }
        static void Main(string[] args)
        {
            TimerDelegate testDelegate = new TimerDelegate(PrintMessage);
            Timer         testTimer    = new Timer(5, 2000, testDelegate);

            Thread thread = new Thread(new ThreadStart(testTimer.Start));

            thread.Start();
        }
示例#21
0
 public Timer(uint interval, TimerDelegate callBackMethod)
 {
     while (true)
     {
         callBackMethod();
         TimeSpan timeSpan = TimeSpan.FromSeconds(interval);
         Thread.Sleep(timeSpan);
     }
 }
        static void Main(string[] args)
        {
            TimerDelegate timerElapsedDelegate = new TimerDelegate(PrintMessage);

            Timer testTimer = new Timer(5, 1, timerElapsedDelegate);

            Thread thread = new Thread(new ThreadStart(testTimer.Start));
            thread.Start();
        }
示例#23
0
        public void AddTimerText(TextBlock tb, int start, int last)
        {
            TimerDelegate tt = new TimerDelegate();

            tt.textBlock = tb;
            tt.start     = start;
            tt.last      = last;
            this.AddTimer(tt);
        }
示例#24
0
 static void Main()
 {
     TimerDelegate d = new TimerDelegate(Timer);
     d(5);
     Console.WriteLine();
     Timer test = new Timer(20, 500, d);
     Thread thread=new Thread(new ThreadStart(test.Run));
     thread.Start();
 }
示例#25
0
 static void Main(string[] args)
 {
     while (true)
     {
         TimerDelegate d = new TimerDelegate(PrinSomeWord);
         d("blaaa");
         Thread.Sleep(delay * 1000);
     }
 }
示例#26
0
    static void Main()
    {
        TimerDelegate timer = new TimerDelegate(SampleMethod);

        while (true)
        {
            timer(2.0);
        }
    }
示例#27
0
        public void AddTimerDelegate(CommonModels.TimerDelegeFunction function, object a, int start, int last)
        {
            TimerDelegate td = new TimerDelegate();

            td.a        = a;
            td.function = function;
            td.start    = start;
            td.last     = last;
            this.AddTimer(td);
        }
示例#28
0
        /// <summary>
        /// 添加定时任务 指定触发的时间  2017年8月6日18:44:33
        /// </summary>
        public void AddTimerEvent(DateTime datetime, TimerDelegate timeDelegate)
        {
            long delayTime = datetime.Ticks - DateTime.Now.Ticks;

            if (delayTime <= 0)
            {
                return;
            }
            AddTimerEvent(delayTime, timeDelegate);
        }
示例#29
0
 private void DislayMessage(string message, int timesToDisplayMessage)
 {
     displayMessage = Message; //set the message to the delegate
     while (timesToDisplayMessage > 0) //display the message n times with t second intervals
     {
         displayMessage(message);
         Thread.Sleep(Seconds);
         timesToDisplayMessage--;
     }
 }
示例#30
0
 public void RemoveFrameRoutine(TimerDelegate handler, bool rightNow = false)
 {
     foreach (FrameRoutine t in FrameRoutineList)
     {
         if (t.Handler == handler)
         {
             t.Destroyed = true;
         }
     }
 }
示例#31
0
        public static ulong Register(float delay, float interval, TimerDelegate onTimer, int times)
        {
            T timer = GetInstance();

            if (timer == null)
            {
                return(0L);
            }
            return(timer.RegisterInternal(null, delay, interval, null, onTimer, null, times));
        }
示例#32
0
        /// <summary>
        /// 添加计时任务
        /// </summary>
        /// <param name="dealyTime"></param>
        /// <param name="td"></param>
        public void AddTimerEvent(float dealyTime, TimerDelegate td)
        {
            if (dealyTime <= 0)
            {
                return;
            }
            TimerModel model = new TimerModel(id.AddGet(), DateTime.Now.Ticks + (long)(dealyTime * 10000000.0), td);

            idModelDic.TryAdd(model.id, model);
        }
示例#33
0
 public static void ExecutedMethod(TimerDelegate method, int seconds, int duration)
 {
     long start = 0;
     while (start <= duration )
     {
         method();
         Thread.Sleep(seconds * 1000);
         start = start + seconds;
     }
 }
示例#34
0
        public static ulong Register(float timeout, TimeoutDelegate onTimer, TimerDelegate onCanceled, int times)
        {
            T timer = GetInstance();

            if (timer == null)
            {
                return(0L);
            }
            return(timer.RegisterInternal(null, timeout, timeout, onTimer, null, onCanceled, times));
        }
示例#35
0
 public Timer(uint id, uint delay, bool repeat, TimerDelegate callback, object cookie, uint now)
 {
     this.isKilled = false;
     this.Id       = id;
     this.Delay    = delay;
     this.Repeat   = repeat;
     this.Callback = callback;
     this.Cookie   = cookie;
     this.TimeFire = now + this.Delay;
 }
示例#36
0
 private void DislayMessage(string message, int timesToDisplayMessage)
 {
     displayMessage = Message;         //set the message to the delegate
     while (timesToDisplayMessage > 0) //display the message n times with t second intervals
     {
         displayMessage(message);
         Thread.Sleep(Seconds);
         timesToDisplayMessage--;
     }
 }
示例#37
0
 // This method repeat other method after some time in some duration
 public static void RepeatSomeMethod(TimerDelegate method, int seconds, long durationInSeconds)
 {
     long start = 0;
     while (start <= durationInSeconds)
     {
         method();
         Thread.Sleep(seconds * 1000);
         start += seconds;
     }
 }
示例#38
0
文件: Timer.cs 项目: KaloyanBobev/OOP
        public static void StartTimer(TimerDelegate method, int interval, long duration)
        {
            long start = 0;

               while (duration >= start)
               {
               method();
               Thread.Sleep(interval * 1000);
               start += interval;
               }
        }
示例#39
0
        public static void RepeatSomeMethod(TimerDelegate method, int seconds, long durationInSeconds)
        {
            long start = 0;

            while (start <= durationInSeconds)
            {
                method();
                Thread.Sleep(seconds * 500);
                start = start + seconds;
            }
        }
示例#40
0
    static void Main()
    {
        Timer obj = new Timer();

        TimerDelegate timer = new TimerDelegate(obj.TimerMethod);
        while (true)
        {
            Thread.Sleep(1000);
            timer(0);
        }
    }
示例#41
0
 public void ClearTimer(TimerDelegate inTimerDelegate)
 {
     for (int i = 0; i < m_timers.Count; i++)
     {
         if (m_timers[i].onTimer == inTimerDelegate)
         {
             //set the Interval to 0.f and let updateTimers clear it
             m_timers[i].Interval = 0;
         }
     }
 }
示例#42
0
 public bool IsTimerActive(TimerDelegate inTimerDelegate)
 {
     for (int i = 0; i < m_timers.Count; i++)
     {
         if (m_timers[i].onTimer == inTimerDelegate && m_timers[i].Interval > 0f)
         {
             return(true);
         }
     }
     return(false);
 }
示例#43
0
        public void AddTimer(int start, int last, CommonModels.TimerDelegeFunction function = null, object a = null, TextBlock tb = null)
        {
            TimerDelegate td = new TimerDelegate();

            td.a         = a;
            td.function  = function;
            td.start     = start;
            td.last      = last;
            td.textBlock = tb;
            this.AddTimer(td);
        }
示例#44
0
        public static void Start(TimerDelegate method, int secondsDelay, int totalSeconds)
        {
            long start = 0;

            while (start <= totalSeconds)
            {
                method();
                Thread.Sleep(secondsDelay * 1000);
                start += secondsDelay;
            }
        }
示例#45
0
 static void Main()
 {
     TimerDelegate timerDelegate = new TimerDelegate(Timer.PrintTime);
     
     int i = 0;
     //Start timer for 1 minute
     while (i < 60)
     {
         timerDelegate(1);
         i++;
     }
 }
示例#46
0
        static void Main()
        {
            int ticks = 10;
            int interval = 2000;// milliseconds

            TimerDelegate timerElapsed = new TimerDelegate(ShowTicksLeft);

            Timer timer = new Timer(ticks, interval, timerElapsed);

            Console.WriteLine("Timer started for {0} ticks, a tick occurring once every {1} second(s).", ticks, interval / 1000);

            Thread timerThread = new Thread(new ThreadStart(timer.Run));
            timerThread.Start();
        }
示例#47
0
文件: Timer.cs 项目: khaha2210/radio
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="elapsedDelegate">The delegate to execute on a timer.</param>
		/// <param name="stateObject">A user defined state object.</param>
		/// <param name="intervalMilliseconds">The time to wait in milliseconds.</param>
		public Timer(TimerDelegate elapsedDelegate, object stateObject, int intervalMilliseconds)
		{
			_synchronizationContext = SynchronizationContext.Current;

			Platform.CheckForNullReference(_synchronizationContext, "SynchronizationContext.Current");
			Platform.CheckForNullReference(elapsedDelegate, "elapsedDelegate");
			
			_stateObject = stateObject; 
			_elapsedDelegate = elapsedDelegate;

			_startStopLock = new object();
			_state = State.Stopped;
			_intervalMilliseconds = intervalMilliseconds;
		}
示例#48
0
 static void Main()
 {
     /*7.	Using delegates write a class Timer that has can execute certain method at each t seconds.*/
     Console.Write("Enter seconds: ");
     int secondsOfDelay = int.Parse(Console.ReadLine());
     if (secondsOfDelay < 0)
     {
         throw new ArgumentOutOfRangeException(String.Format("Seconds must be positive. Enter value: {0}", secondsOfDelay));
     }
     else
     {
         TimerDelegate test = new TimerDelegate(Timer.PrintDate);
         test(secondsOfDelay);
     }
     Console.WriteLine("Main thread exits.");
 }
示例#49
0
 /// <summary>
 /// AddTimer will add a new timer provided a timer of the same name does not already exist.
 /// </summary>
 /// <param name="sTimerName">Name of timer to be added</param>
 /// <param name="fTimerDuration">Duration timer should last, in seconds</param>
 /// <param name="Callback">Call back delegate which should be called when the timer expires</param>
 /// <param name="bLooping">Whether the timer should loop infinitely, or should fire once and remove itself</param>
 /// <returns>Returns true if the timer was successfully added, false if it wasn't</returns>
 public bool AddTimer(string sTimerName, float fTimerDuration, TimerDelegate Callback, bool bLooping)
 {
     if (!m_kTimers.ContainsKey(sTimerName))
     {
        // Console.WriteLine(sTimerName);
         TimerInstance t = new TimerInstance();
         t.sTimerName = sTimerName;
         t.fTotalTime = fTimerDuration*1000;
         t.OnTimer += Callback;
         t.bLooping = bLooping;
         t.bRemove = false;
         t.fRemainingTime = fTimerDuration*1000;
         t.iTriggerCount = 0;
         m_kTimers.Add(sTimerName, t);
         return true;
     }
     return false;
 }
        /// <summary>
        /// AddTimer will add a new timer provided a timer of the same name does not already exist.
        /// </summary>
        /// <param name="sTimerName">Name of timer to be added</param>
        /// <param name="fTimerDuration">Duration timer should last, in seconds</param>
        /// <param name="Callback">Call back delegate which should be called when the timer expires</param>
        /// <param name="bLooping">Whether the timer should loop infinitely, or should fire once and remove itself</param>
        /// <returns>Returns true if the timer was successfully added, false if it wasn't</returns>
        public bool AddTimer(string sTimerName, float fTimerDuration, TimerDelegate Callback, bool bLooping)
        {
            TimerInstance newTimer = new TimerInstance();
            if (m_kTimers.ContainsKey(sTimerName) == true)
            {
                return false;
            }
            else
            {
                newTimer.sTimerName = sTimerName;
                newTimer.fTotalTime = fTimerDuration;
                newTimer.fRemainingTime = fTimerDuration;
                newTimer.bRemove = false;
                newTimer.OnTimer += Callback;
                newTimer.bLooping = bLooping;
                newTimer.iTriggerCount = 0;

                m_kTimers.Add(sTimerName, newTimer);

                return true;
            }
        }
示例#51
0
 public Timer(TimerDelegate methodToCall, int ticksCount, int interval)
 {
     this.methodToCall = methodToCall;
     this.TicksCount = ticksCount;
     this.Interval = interval;
 }
示例#52
0
 public ITimerSite CreateTimer(int interval, TimerDelegate callback)
 {
     return new TimerSite(interval, callback);
 }
示例#53
0
 public TimerSite(int interval, TimerDelegate callback)
 {
     _callback = callback;
     _timer = new Timer();
     _timer.Interval = interval;
     _timer.Tick += delegate(object sender, EventArgs ars) {
         try {
             _callback();
         }
         catch (Exception ex) {
             RuntimeUtil.ReportException(ex);
         }
     };
     _timer.Enabled = true;
 }
示例#54
0
        private void ResTimerMethod(object source, ElapsedEventArgs e)
        {
            TimerDelegate msgDelegate = null;

             try
             {
                 //  The AccessForm routine contains the code that accesses the form.
                 msgDelegate = new TimerDelegate(ComputeRes);

                 //  send new fb.
                 base.BeginInvoke(msgDelegate, null);
             }
             catch (Exception ex)
             {
                 throw ex;
             }
        }
示例#55
0
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="elapsedDelegate">The delegate to execute on a timer.</param>
		/// <param name="stateObject">A user defined state object.</param>
		public Timer(TimerDelegate elapsedDelegate, object stateObject)
			: this(elapsedDelegate, stateObject, 1000)
		{
		}
示例#56
0
    public void Create(uint dueTime, uint period, TimerDelegate callback)
    {
        if (_Enabled)
            return;

        TimerCallback = callback;
        bool Success = CreateTimerQueueTimer(ref Handle, IntPtr.Zero, TimerCallback, IntPtr.Zero, dueTime, period, 0);

        if (!Success)
            ThrowNewException("CreateTimerQueueTimer");
        _Enabled = Success;
    }
示例#57
0
 public static void Main()
 {
     TimerDelegate ticTac = new TimerDelegate(PrintOnSecond);
     ticTac(1);
 }
示例#58
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="elapsedDelegate">The delegate to execute on a timer.</param>
        /// <param name="stateObject">A user defined state object.</param>
        /// <param name="interval">The timer interval.</param>
        public Timer(TimerDelegate elapsedDelegate, object stateObject, TimeSpan interval)
			: this(elapsedDelegate, stateObject, (int)interval.TotalMilliseconds)
		{
		}
示例#59
0
        private TimerDelegate callback; //new delegate field

        #endregion Fields

        #region Constructors

        // constructor
        public Timer(int tickCounter, int interval, TimerDelegate callback)
        {
            this.TickCounter = tickCounter;
            this.Interval = interval;
            this.callback = callback;
        }
示例#60
0
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="elapsedDelegate">The delegate to execute on a timer.</param>
		public Timer(TimerDelegate elapsedDelegate)
			: this(elapsedDelegate, null)
		{ 
		}