コード例 #1
0
        /// <summary>
        /// Schedules an action to be executed at dueTime.
        /// </summary>
        /// <typeparam name="TAbsolute">Absolute time representation type.</typeparam>
        /// <typeparam name="TRelative">Relative time representation type.</typeparam>
        /// <param name="scheduler">Scheduler to execute the action on.</param>
        /// <param name="dueTime">Relative time after which to execute the action.</param>
        /// <param name="action">Action to be executed.</param>
        /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
        public static IDisposable ScheduleRelative <TAbsolute, TRelative>(this VirtualTimeSchedulerBase <TAbsolute, TRelative> scheduler, TRelative dueTime, Action action)
            where TAbsolute : IComparable <TAbsolute>
        {
            if (scheduler == null)
            {
                throw new ArgumentNullException("scheduler");
            }
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            return(scheduler.ScheduleRelative(action, dueTime, Invoke));
        }
コード例 #2
0
        /// <summary>
        /// Schedules an action to be executed at <paramref name="dueTime"/>.
        /// </summary>
        /// <typeparam name="TAbsolute">Absolute time representation type.</typeparam>
        /// <typeparam name="TRelative">Relative time representation type.</typeparam>
        /// <param name="scheduler">Scheduler to execute the action on.</param>
        /// <param name="dueTime">Relative time after which to execute the action.</param>
        /// <param name="action">Action to be executed.</param>
        /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
        public static IDisposable ScheduleRelative <TAbsolute, TRelative>(this VirtualTimeSchedulerBase <TAbsolute, TRelative> scheduler, TRelative dueTime, Action action)
            where TAbsolute : IComparable <TAbsolute>
        {
            if (scheduler == null)
            {
                throw new ArgumentNullException(nameof(scheduler));
            }
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            // As stated in Scheduler.Simple.cs,
            // an anonymous delegate will allow delegate caching.
            // Watch https://github.com/dotnet/roslyn/issues/5835 for compiler
            // support for caching delegates from method groups.
            return(scheduler.ScheduleRelative(action, dueTime, (s, a) => Invoke(s, a)));
        }