Пример #1
0
        override internal void Execute(object[] args)
        {
            if (args.Length != 3)
            {
                throw new ArgumentException();
            }

            if (!(args [0] is IEnumerable <T>))
            {
                throw new ArgumentException();
            }

            if (args [1] == null || !(args [1] is ChildFunc <T>))
            {
                throw new ArgumentException();
            }

            if (args [args.Length - 1] == null || !(args [args.Length - 1] is UAsyncFinalFunc))
            {
                throw new ArgumentException();
            }

            IsDone      = false;
            IsFree      = false;
            completeNum = 0;
            var temp = (IEnumerable <T>)args [0];

            items.Clear();
            items.AddRange(temp.ToList());
            total     = items.Count;
            finalFunc = args [args.Length - 1] as UAsyncFinalFunc;

            if (total == 0)
            {
                IsDone = true;
                IsFree = true;
                finalFunc.action2(null);
                return;
            }

            func = args [1] as ChildFunc <T>;
            RunOneFunc();
        }
Пример #2
0
        internal override void Execute(object[] args)
        {
            if (args.Length != 3)
            {
                throw new ArgumentException();
            }

            if (!(args [0] is IEnumerable <T>))
            {
                throw new ArgumentException();
            }

            if (args [1] == null || !(args [1] is ChildFunc <T>))
            {
                throw new ArgumentException();
            }

            if (args [args.Length - 1] == null || !(args [args.Length - 1] is UAsyncFinalFunc))
            {
                throw new ArgumentException();
            }

            IsDone      = false;
            IsFree      = false;
            completeNum = 0;
            var temp = (IEnumerable <T>)args [0];

            items.Clear();
            items.AddRange(temp.ToList());
            total     = items.Count;
            finalFunc = args [args.Length - 1] as UAsyncFinalFunc;

            if (total == 0)
            {
                IsDone = true;
                IsFree = true;
                finalFunc.action2(null);
                return;
            }

            taskRoutines.Clear();
            func = args [1] as ChildFunc <T>;

            for (var i = 0; i < total; i++)
            {
                var item = items [i];

                if (func.action1 != null)
                {
                    taskRoutines.Add(
                        TaskRunner.Instance.Run(
                            new SingleTask(() => func.action1(item, Callback)),
                            TaskRunnerCallback)
                        );
                }
                else
                {
                    taskRoutines.Add(
                        TaskRunner.Instance.Run(
                            func.enumerator1(item, Callback),
                            TaskRunnerCallback)
                        );
                }
            }
        }