Example #1
0
        /// <summary>
        /// Provides a method to finish one or more task, after completion of supplied finshed task.
        /// </summary>
        /// <param name="finishedtask">The task which will check for cmpletion.</param>
        /// <param name="returns">The <see cref="TaskResult"/> that defines the current status of a task.</param>
        /// <param name="p">The array of tasks, which will be executed.</param>
        public void Return(ITask finishedtask, TaskResult returns, params object[] p)
        {
            if (finishedtask.Origin == null) return;

            // This only occurs when a task is started with Task.Empty as origin, that is, the starting task
            if (finishedtask.Origin == Task.Empty) finishedtask.Continue(finishedtask.Name, returns, p);

            tasks.Remove(finishedtask.Id);

            MethodInfo continuedirectmethod = finishedtask.Origin.GetType().GetMethod(string.Format("Continue{0}From{1}", returns.Name, finishedtask.Name), p.Select(param => param == null ? typeof(object) : param.GetType()).ToArray());

            if (continuedirectmethod == null)
            {
                finishedtask.Origin.Continue(finishedtask.Name, returns, p);
            }
            else
            {
                continuedirectmethod.Invoke(finishedtask.Origin, p);
            }
        }