Beispiel #1
0
        /// <summary>
        /// Registers a method invocation as a timed task within the context.
        /// </summary>
        /// <param name="interval">The interval between method executions.</param>
        /// <param name="method">The method which must execute.</param>
        /// <param name="instance">The object instance which the method must execute against.</param>
        public void Register(ITimedInterval interval, MethodInfo method, object instance)
        {
            if (interval == null)
            {
                throw new ArgumentException("Cannot register a timed task with no interval", "interval");
            }

            if (instance == null && !method.IsStatic)
            {
                throw new ArgumentException($"Cannot register a non-static method without a target instance for '{method.DeclaringType.FullName}.{method.Name}'");
            }

            var handler = CreateTimedIntervalHandler(method);
            var task    = new TimedIntervalTask(interval, handler, instance);

            timedTasks.Add(task);
            timedThread.Add(task);
        }