Exemplo n.º 1
0
		/// <summary>
		/// Trigger a Scheduled Method to be run withing given delay
		/// </summary>
		/// <param name="method">Method to be scheduled, return next interval or 0 for single run</param>
		/// <param name="delay">delay in ms for the Method to be started</param>
		/// <returns>The Scheduled Task Object</returns>
		public ScheduledTask Start(Func<int> method, int delay)
		{
			if (delay < 1)
				throw new ArgumentException("Task Delay should be greater than 0.", "delay");
			
			var task = new ScheduledTask(method);
			
			Start(task, delay);
			
			return task;
		}
Exemplo n.º 2
0
		/// <summary>
		/// Add or Re Schedule Task Object
		/// </summary>
		/// <param name="task">Scheduled Task Object to Add</param>
		/// <param name="delay">Delay before Scheduled Task is triggered</param>
		private void Start(ScheduledTask task, int delay)
		{
			var dueTime = Ticks + delay;
			PendingTimers.Add(new Tuple<long, ScheduledTask>(dueTime, task));
			
			SignalNextDueTick(dueTime);
		}
Exemplo n.º 3
0
		/// <summary>
		/// Start a Task Method
		/// </summary>
		/// <param name="task"></param>
		private void LaunchScheduledTask(ScheduledTask task)
		{
			int delay = 0;
			var start = Ticks;
			try
			{
				delay = task.Run();
			}
			catch (Exception ex)
			{
				if (log.IsErrorEnabled)
					log.Error("Exception In Simple Scheduler Task: ", ex);
			}
			
			if (log.IsWarnEnabled)
			{
				var runningTime = Ticks - start;
				if (runningTime > 500)
					log.WarnFormat("Simple Scheduler Task (interval:{1}) execution took {0}ms! ({2}.{3})", runningTime, delay, task.Method.GetMethodInfo().ReflectedType, task.Method.GetMethodInfo().Name);
			}
			
			if (delay > 0 && task.Active)
				Start(task, delay);
		}