コード例 #1
0
ファイル: Program.cs プロジェクト: nomada2/Experiments
        private void ProcessOperation(OperationData data)
        {
            // Time and run the operation's delegate
            data.Start = DateTimeOffset.Now;
            if (data.Context != null)
            {
                ExecutionContext.Run(data.Context.CreateCopy(),
                                     op => ((OperationData)op).Operation(), data);
            }
            else
            {
                data.Operation();
            }
            data.End = DateTimeOffset.Now;


            // Raise the operation completed event
            OnOperationCompleted(data);

            // Signal to all that depend on this operation of its
            // completion, and potentially launch newly available
            lock (_stateLock)
            {
                List <int> toList;
                if (_dependenciesFromTo.TryGetValue(data.Id, out toList))
                {
                    foreach (int targetId in toList)
                    {
                        OperationData targetData = _operations[targetId];
                        if (--targetData.NumRemainingDependencies == 0)
                        {
                            QueueOperation(targetData);
                        }
                    }
                }
                _dependenciesFromTo.Remove(data.Id);


                if (--_remainingCount == 0)
                {
                    done.Set();
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: nomada2/Experiments
        public void AddOperation(
            int id, Action operation, params int[] dependencies)
        {
            if (operation == null)
            {
                throw new ArgumentNullException("operation");
            }
            if (dependencies == null)
            {
                throw new ArgumentNullException("dependencies");
            }

            var data = new OperationData
            {
                Context      = ExecutionContext.Capture(),
                Id           = id,
                Operation    = operation,
                Dependencies = dependencies
            };

            _operations.Add(id, data);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: nomada2/Experiments
 private void QueueOperation(OperationData data)
 {
     ThreadPool.UnsafeQueueUserWorkItem(state =>
                                        ProcessOperation((OperationData)state), data);
 }