Example #1
0
        /// <summary>
        /// Enqueues a task for asynchronous execution on the next tick.
        /// </summary>
        /// <param name="action">The action that will be invoked on the next tick.</param>
        public TaskHandle RunTaskAsync(Action action)
        {
            TaskHandle handle;

            Monitor.Enter(taskQueue);

            Task task = new Task(action, true, 0);

            taskQueue.Enqueue(task);
            handle = new TaskHandle(task);

            Monitor.Exit(taskQueue);

            return(handle);
        }
Example #2
0
        /// <summary>
        /// Enqueues a task for periodic asynchronous execution.
        /// </summary>
        /// <param name="action">The action that will be invoked when the delay is over and then everytime the interval is over.</param>
        /// <param name="delay">The delay in ticks.</param>
        /// <param name="interval">The interval in ticks.</param>
        public TaskHandle RunPeriodicTaskAsync(Action action, int delay, int interval)
        {
            TaskHandle handle;

            Monitor.Enter(taskQueue);

            Task task = new PeriodicTask(action, true, interval, delay);

            taskQueue.Enqueue(task);
            handle = new TaskHandle(task);

            Monitor.Exit(taskQueue);

            return(handle);
        }
Example #3
0
        /// <summary>
        /// Enqueues a task for delayed synchronous execution.
        /// </summary>
        /// <param name="action">The action that will be invoked when the delay is over.</param>
        /// <param name="delay">The delay in ticks.</param>
        public TaskHandle RunDelayedTask(Action action, int delay)
        {
            TaskHandle handle;

            Monitor.Enter(taskQueue);

            Task task = new Task(action, false, delay);

            taskQueue.Enqueue(task);
            handle = new TaskHandle(task);

            Monitor.Exit(taskQueue);

            return(handle);
        }