MethodQ.cs
/// <summary>
/// Schedules the specified action to be executed ONCE at the specified <paramref name="executionUtc"/> <see cref="DateTime"/>.
/// </summary>
/// <param name="action">The <see cref="Action"/> to schedule.</param>
/// <param name="executionUtc">The <see cref="DateTime"/> in UTC of when the <paramref name="action"/> should be invoked.</param>
/// <returns>The scheduled method call's unique identifier (needed for cancellation).</returns>
Schedules the specified action to be executed ONCE at the specified  .
Schedules the specified action to be executed ONCE at the specified .
public ulong Schedule(Action action, DateTime executionUtc)
        {
            if (action is null)
                throw new ArgumentNullException($"{nameof(MethodQ)}::{nameof(Schedule)}: The provided {nameof(action)} argument is null!");
            var utcNow = DateTime.UtcNow;
            if (executionUtc < utcNow)
                throw new ArgumentException($"{nameof(MethodQ)}::{nameof(Schedule)}: The provided {nameof(executionUtc)} {nameof(DateTime)} lies in the past! The {nameof(action)} wouldn't be executed at all!");
            var deltaTime = executionUtc - utcNow;
            if (deltaTime.TotalMilliseconds >= Int32.MaxValue)
                throw new ArgumentException($"{nameof(MethodQ)}::{nameof(Schedule)}: The provided {nameof(executionUtc)} {nameof(DateTime)} lies more than {{Int32.MaxValue}} milliseconds in the future, which is not allowed and not a good idea anyway (use a scheduled task for anything >3 days in the future).");
            ulong id = nextId++;
            var timer = new Timer(deltaTime.TotalMilliseconds) { AutoReset = false };
            timer.Elapsed += (_, __) =>
            {
                action.Invoke();
                timer.Dispose();
                timers.Remove(id);
            };
            timer.Start();
            timers.Add(id, timer);
            return id;
        }
public ulong Schedule ( Action action , DateTime executionUtc ) { if ( action is null ) throw new ArgumentNullException ( $" { nameof ( MethodQ ) } :: { nameof ( Schedule ) } : The provided  { nameof ( action ) }  argument is null! " ) ; var utcNow = DateTime . UtcNow ; if ( executionUtc < utcNow ) throw new ArgumentException ( $" { nameof ( MethodQ ) } :: { nameof ( Schedule ) } : The provided  { nameof ( executionUtc ) } { nameof ( DateTime ) }  lies in the past! The  { nameof ( action ) }  wouldn't be executed at all! " ) ; var deltaTime = executionUtc - utcNow ; if ( deltaTime . TotalMilliseconds >= Int32 . MaxValue ) throw new ArgumentException ( $" { nameof ( MethodQ ) } :: { nameof ( Schedule ) } : The provided  { nameof ( executionUtc ) } { nameof ( DateTime ) }  lies more than  {{ Int32.MaxValue}} milliseconds in the future, which is not allowed and not a good idea anyway (use a scheduled task for anything >3 days in the future). " ) ; ulong id = nextId ++ ; var timer = new Timer ( deltaTime . TotalMilliseconds ) { AutoReset = false } ; timer . Elapsed += ( _ , __ ) => { action . Invoke ( ) ; timer . Dispose ( ) ; timers . Remove ( id ) ; } ; timer . Start ( ) ; timers . Add ( id , timer ) ; return id ; }
Schedules the specified action to be executed ONCE at the specified  .
Schedules the specified action to be executed ONCE at the specified .
The scheduled method call's unique identifier (needed for cancellation).
The scheduled method call ' s unique identifier ( needed for cancellation ) .
action
Action
The  to schedule.
The to schedule .
executionUtc
DateTime
The  in UTC of when the  should be invoked.
The in UTC of when the should be invoked .