示例#1
0
        internal Task(TaskActionInvoker invoker, object state, CancellationToken cancellationToken,
                      TaskCreationOptions creationOptions, Task parent)
        {
            this.invoker             = invoker;
            this.taskCreationOptions = creationOptions;
            this.state  = state;
            this.taskId = Interlocked.Increment(ref id);
            this.status = cancellationToken.IsCancellationRequested ? TaskStatus.Canceled : TaskStatus.Created;
            this.token  = cancellationToken;
            this.parent = parent;

            // Process taskCreationOptions
            if (CheckTaskOptions(taskCreationOptions, TaskCreationOptions.AttachedToParent) && parent != null)
            {
                parent.AddChild();
            }

            if (token.CanBeCanceled)
            {
                cancellationRegistration = token.Register(l => ((Task)l).CancelReal(), this);
            }
        }
示例#2
0
        public Task ContinueWith(Action <Task <TResult>, object> continuationAction, object state, CancellationToken cancellationToken,
                                 TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
        {
            if (continuationAction == null)
            {
                throw new ArgumentNullException("continuationAction");
            }
            if (scheduler == null)
            {
                throw new ArgumentNullException("scheduler");
            }

            var t = new Task(TaskActionInvoker.Create(continuationAction),
                             state,
                             cancellationToken,
                             GetCreationOptions(continuationOptions),
                             this);

            ContinueWithCore(t, continuationOptions, scheduler);

            return(t);
        }
示例#3
0
        public Task <TNewResult> ContinueWith <TNewResult> (Func <Task <TResult>, TNewResult> continuationFunction,
                                                            CancellationToken cancellationToken,
                                                            TaskContinuationOptions continuationOptions,
                                                            TaskScheduler scheduler)
        {
            if (continuationFunction == null)
            {
                throw new ArgumentNullException("continuationFunction");
            }
            if (scheduler == null)
            {
                throw new ArgumentNullException("scheduler");
            }

            var t = new Task <TNewResult> (TaskActionInvoker.Create(continuationFunction),
                                           null,
                                           cancellationToken,
                                           GetCreationOptions(continuationOptions),
                                           this);

            ContinueWithCore(t, continuationOptions, scheduler);

            return(t);
        }
示例#4
0
		internal Task (TaskActionInvoker invoker, object state, CancellationToken cancellationToken,
		               TaskCreationOptions creationOptions, Task parent = null, Task contAncestor = null, bool ignoreCancellation = false)
		{
			this.invoker         = invoker;
			this.creationOptions = creationOptions;
			this.state           = state;
			this.taskId          = Interlocked.Increment (ref id);
			this.token           = cancellationToken;
			this.parent          = parent = parent == null ? current : parent;
			this.contAncestor    = contAncestor;
			this.status          = cancellationToken.IsCancellationRequested && !ignoreCancellation ? TaskStatus.Canceled : TaskStatus.Created;

			// Process creationOptions
#if NET_4_5
			if (parent != null && HasFlag (creationOptions, TaskCreationOptions.AttachedToParent)
			    && !HasFlag (parent.CreationOptions, TaskCreationOptions.DenyChildAttach))
#else
			if (parent != null && HasFlag (creationOptions, TaskCreationOptions.AttachedToParent))
#endif
				parent.AddChild ();

			if (token.CanBeCanceled && !ignoreCancellation)
				cancellationRegistration = token.Register (l => ((Task) l).CancelReal (), this);
		}
示例#5
0
 internal Task(TaskActionInvoker invoker, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions, Task parent, Task contAncestor = null, bool ignoreCancellation = false)
     : base(invoker, state, cancellationToken, creationOptions, parent, contAncestor, ignoreCancellation)
 {
 }
示例#6
0
 internal Task(TaskActionInvoker invoker, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions, Task parent)
     : base(invoker, state, cancellationToken, creationOptions, parent)
 {
 }
示例#7
0
 internal Task(TaskActionInvoker invoker, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions, Task parent, Task contAncestor = null)
     : base(invoker, state, cancellationToken, creationOptions, parent, contAncestor)
 {
 }
示例#8
0
		protected void SetAction (Action<object> action)
		{
			this.invoker = TaskActionInvoker.Create(action);
		}