Esempio n. 1
0
File: Task.cs Progetto: weeble/mono
        internal static Task WhenAllCore(IList <Task> tasks)
        {
            bool all_completed = true;

            foreach (var t in tasks)
            {
                if (t == null)
                {
                    throw new ArgumentException("tasks", "the tasks argument contains a null element");
                }

                all_completed &= t.Status == TaskStatus.RanToCompletion;
            }

            if (all_completed)
            {
                return(TaskConstants.Finished);
            }

            var task = new Task(TaskActionInvoker.Empty, null, CancellationToken.None, TaskCreationOptions.None, null, TaskConstants.Finished);

            task.SetupScheduler(TaskScheduler.Current);

            var continuation = new WhenAllContinuation(task, tasks);

            foreach (var t in tasks)
            {
                t.ContinueWith(continuation);
            }

            return(task);
        }
Esempio n. 2
0
		internal static Task<TResult[]> WhenAllCore<TResult> (IList<Task<TResult>> tasks)
		{
			foreach (var t in tasks) {
				if (t == null)
					throw new ArgumentException ("tasks", "the tasks argument contains a null element");
			}

			var task = new Task<TResult[]> (TaskActionInvoker.Empty, null, CancellationToken.None, TaskCreationOptions.None, null, TaskConstants.Finished);
			task.SetupScheduler (TaskScheduler.Current);

			var continuation = new WhenAllContinuation<TResult> (task, tasks);
			foreach (var t in tasks)
				t.ContinueWith (continuation);

			return task;
		}