GetWorkItemResult() приватный Метод

Returns the work item result
private GetWorkItemResult ( ) : IWorkItemResult
Результат IWorkItemResult
Пример #1
0
        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="callback">A callback to execute</param>
        /// <param name="workItemPriority">The priority of the work item</param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(WorkItemCallback callback, WorkItemPriority workItemPriority)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, workItemPriority);

            Enqueue(workItem);
            return(workItem.GetWorkItemResult());
        }
Пример #2
0
        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="callback">A callback to execute</param>
        /// <param name="workItemPriority">The priority of the work item</param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(WorkItemCallback callback, WorkItemPriority workItemPriority)
        {
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, _workItemsGroupStartInfo, callback,
                                                               workItemPriority);

            EnqueueToSTPNextWorkItem(workItem);
            return(workItem.GetWorkItemResult());
        }
Пример #3
0
        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="workItemInfo">Work item information</param>
        /// <param name="callback">A callback to execute</param>
        /// <param name="state">
        /// The context object of the work item. Used for passing arguments to the work item.
        /// </param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback, object state)
        {
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, _workItemsGroupStartInfo, workItemInfo, callback,
                                                               state);

            EnqueueToSTPNextWorkItem(workItem);
            return(workItem.GetWorkItemResult());
        }
Пример #4
0
        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="workItemInfo">Work item information</param>
        /// <param name="callback">A callback to execute</param>
        /// <param name="state">
        /// The context object of the work item. Used for passing arguments to the work item.
        /// </param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback, object state)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, workItemInfo, callback, state);

            Enqueue(workItem);
            return(workItem.GetWorkItemResult());
        }
Пример #5
0
        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="callback">A callback to execute</param>
        /// <param name="state">
        /// The context object of the work item. Used for passing arguments to the work item.
        /// </param>
        /// <param name="postExecuteWorkItemCallback">
        /// A delegate to call after the callback completion
        /// </param>
        /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state,
                                             PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute);

            Enqueue(workItem);
            return(workItem.GetWorkItemResult());
        }
Пример #6
0
        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="callback">A callback to execute</param>
        /// <param name="state">
        /// The context object of the work item. Used for passing arguments to the work item.
        /// </param>
        /// <param name="postExecuteWorkItemCallback">
        /// A delegate to call after the callback completion
        /// </param>
        /// <param name="workItemPriority">The work item priority</param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(
            WorkItemCallback callback,
            object state,
            PostExecuteWorkItemCallback postExecuteWorkItemCallback,
            WorkItemPriority workItemPriority)
        {
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, workItemPriority);

            Enqueue(workItem);
            return(workItem.GetWorkItemResult());
        }
        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="callback">A callback to execute</param>
        /// <param name="state">
        /// The context object of the work item. Used for passing arguments to the work item.
        /// </param>
        /// <param name="postExecuteWorkItemCallback">
        /// A delegate to call after the callback completion
        /// </param>
        /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param>
        /// <param name="workItemPriority">The work item priority</param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(
            WorkItemCallback callback,
            object state,
            PostExecuteWorkItemCallback postExecuteWorkItemCallback,
            CallToPostExecute callToPostExecute,
            WorkItemPriority workItemPriority)
        {
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, _workItemsGroupStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority);

            EnqueueToSTPNextWorkItem(workItem);
            return(workItem.GetWorkItemResult());
        }
        public IWorkItemResult <TResult> QueueWorkItem <TResult>(Func <TResult> func)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                this,
                WIGStartInfo,
                state =>
            {
                return(func.Invoke());
            });

            Enqueue(workItem);
            return(new WorkItemResultTWrapper <TResult>(workItem.GetWorkItemResult()));
        }
Пример #9
0
        public IWorkItemResult <TResult> QueueWorkItem <TResult>(Func <TResult> func, WorkItemPriority priority = SmartThreadPool.DefaultWorkItemPriority)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                this,
                WIGStartInfo,
                state =>
            {
                return(func.Invoke());
            }, priority);

            Enqueue(workItem);
            return(new WorkItemResultTWrapper <TResult>(workItem.GetWorkItemResult()));
        }
        public IWorkItemResult <TResult> QueueWorkItem <T1, T2, TResult>(Func <T1, T2, TResult> func, T1 arg1, T2 arg2)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                this,
                WIGStartInfo,
                state =>
            {
                return(func.Invoke(arg1, arg2));
            },
                WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null);

            Enqueue(workItem);
            return(new WorkItemResultTWrapper <TResult>(workItem.GetWorkItemResult()));
        }
        public IWorkItemResult QueueWorkItem(Action action, WorkItemPriority priority)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                this,
                WIGStartInfo,
                delegate
            {
                action.Invoke();
                return(null);
            }, priority);

            Enqueue(workItem);
            return(workItem.GetWorkItemResult());
        }
Пример #12
0
        public IWorkItemResult <TResult> QueueWorkItem <T1, T2, TResult>(Func <T1, T2, TResult> func, T1 arg1, T2 arg2, WorkItemPriority priority = SmartThreadPool.DefaultWorkItemPriority)
        {
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                this,
                WIGStartInfo,
                state =>
            {
                return(func.Invoke(arg1, arg2));
            },
                WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null,
                priority);

            Enqueue(workItem);
            return(new WorkItemResultTWrapper <TResult>(workItem.GetWorkItemResult()));
        }
Пример #13
0
        public IWorkItemResult QueueWorkItem <T1, T2>(Action <T1, T2> action, T1 arg1, T2 arg2, WorkItemPriority priority = SmartThreadPool.DefaultWorkItemPriority)
        {
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                this,
                WIGStartInfo,
                state =>
            {
                action.Invoke(arg1, arg2);
                return(null);
            },
                WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null, priority);

            Enqueue(workItem);
            return(workItem.GetWorkItemResult());
        }
        public IWorkItemResult QueueWorkItem <T1, T2, T3>(Action <T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3, WorkItemPriority priority)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                this,
                WIGStartInfo,
                state =>
            {
                action.Invoke(arg1, arg2, arg3);
                return(null);
            },
                WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3 } : null, priority);

            Enqueue(workItem);
            return(workItem.GetWorkItemResult());
        }
        public IWorkItemResult QueueWorkItem <T1, T2>(Action <T1, T2> action, T1 arg1, T2 arg2)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                this,
                WIGStartInfo,
                delegate
            {
                action.Invoke(arg1, arg2);
                return(null);
            },
                WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null);

            Enqueue(workItem);
            return(workItem.GetWorkItemResult());
        }
Пример #16
0
        public IWorkItemResult <TResult> QueueWorkItem <T, TResult>(Func <T, TResult> func, T arg, WorkItemPriority priority = WorkItemPriority.Normal)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                this,
                WIGStartInfo,
                state =>
            {
                return(func.Invoke(arg));
            },
                WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null,
                priority);

            Enqueue(workItem);
            return(new WorkItemResultTWrapper <TResult>(workItem.GetWorkItemResult()));
        }
Пример #17
0
        public IWorkItemResult QueueWorkItem <T> (Action <T> action, T arg)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                this,
                WIGStartInfo,
                state =>
            {
                action.Invoke(arg);
                return(null);
            },
                WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null);

            Enqueue(workItem);
            return(workItem.GetWorkItemResult());
        }
Пример #18
0
        private void EnqueueToSTPNextWorkItem(WorkItem workItem, bool decrementWorkItemsInStpQueue)
        {
            lock (_lock)
            {
                // Got here from OnWorkItemCompletedCallback()
                if (decrementWorkItemsInStpQueue)
                {
                    --_workItemsInStpQueue;

                    if (_workItemsInStpQueue < 0)
                    {
                        _workItemsInStpQueue = 0;
                    }

                    --_workItemsExecutingInStp;

                    if (_workItemsExecutingInStp < 0)
                    {
                        _workItemsExecutingInStp = 0;
                    }
                }

                // If the work item is not null then enqueue it
                if (null != workItem)
                {
                    workItem.CanceledWorkItemsGroup = _canceledWorkItemsGroup;

                    RegisterToWorkItemCompletion(workItem.GetWorkItemResult());
                    _workItemsQueue.Enqueue(workItem);
                    //_stp.IncrementWorkItemsCount();

                    if ((1 == _workItemsQueue.Count) &&
                        (0 == _workItemsInStpQueue))
                    {
                        _stp.RegisterWorkItemsGroup(this);
                        IsIdle = false;
                        _isIdleWaitHandle.Reset();
                    }
                }

                // If the work items queue of the group is empty than quit
                if (0 == _workItemsQueue.Count)
                {
                    if (0 == _workItemsInStpQueue)
                    {
                        _stp.UnregisterWorkItemsGroup(this);
                        IsIdle = true;
                        _isIdleWaitHandle.Set();
                        if (decrementWorkItemsInStpQueue && _onIdle != null && _onIdle.GetInvocationList().Length > 0)
                        {
                            _stp.QueueWorkItem(new WorkItemCallback(FireOnIdle));
                        }
                    }
                    return;
                }

                if (!_isSuspended)
                {
                    if (_workItemsInStpQueue < _concurrency)
                    {
                        WorkItem nextWorkItem = _workItemsQueue.Dequeue() as WorkItem;
                        try
                        {
                            _stp.Enqueue(nextWorkItem);
                        }
                        catch (ObjectDisposedException e)
                        {
                            e.GetHashCode();
                            // The STP has been shutdown
                        }

                        ++_workItemsInStpQueue;
                    }
                }
            }
        }
Пример #19
0
        private void EnqueueToSTPNextWorkItem(WorkItem workItem, bool decrementWorkItemsInStpQueue)
        {
            lock(_lock)
            {
                // Got here from OnWorkItemCompletedCallback()
                if (decrementWorkItemsInStpQueue)
                {
                    --_workItemsInStpQueue;

                    if(_workItemsInStpQueue < 0)
                    {
                        _workItemsInStpQueue = 0;
                    }

                    --_workItemsExecutingInStp;

                    if(_workItemsExecutingInStp < 0)
                    {
                        _workItemsExecutingInStp = 0;
                    }
                }

                // If the work item is not null then enqueue it
                if (null != workItem)
                {
                    workItem.CanceledWorkItemsGroup = _canceledWorkItemsGroup;

                    RegisterToWorkItemCompletion(workItem.GetWorkItemResult());
                    _workItemsQueue.Enqueue(workItem);
                    //_stp.IncrementWorkItemsCount();

                    if ((1 == _workItemsQueue.Count) &&
                        (0 == _workItemsInStpQueue))
                    {
                        _stp.RegisterWorkItemsGroup(this);
                        IsIdle = false;
                        _isIdleWaitHandle.Reset();
                    }
                }

                // If the work items queue of the group is empty than quit
                if (0 == _workItemsQueue.Count)
                {
                    if (0 == _workItemsInStpQueue)
                    {
                        _stp.UnregisterWorkItemsGroup(this);
                        IsIdle = true;
                        _isIdleWaitHandle.Set();
                        if (decrementWorkItemsInStpQueue)
                        {
                            _stp.QueueWorkItem(new WorkItemCallback(FireOnIdle));
                        }
                    }
                    return;
                }

                if (!_isSuspended)
                {
                    if (_workItemsInStpQueue < _concurrency)
                    {
                        WorkItem nextWorkItem = _workItemsQueue.Dequeue() as WorkItem;
                        try
                        {
                            _stp.Enqueue(nextWorkItem);
                        }
                        catch (ObjectDisposedException e)
                        {
                            e.GetHashCode();
                            // The STP has been shutdown
                        }

                        ++_workItemsInStpQueue;
                    }
                }
            }
        }
Пример #20
0
        private void EnqueueToSTPNextWorkItem(WorkItem workItem, bool decrementWorkItemsInStpQueue)
        {
            lock (_lock)
            {
                // Got here from OnWorkItemCompletedCallback()
                if (decrementWorkItemsInStpQueue)
                {
                    --_workItemsInStpQueue;

                    if (_workItemsInStpQueue < 0)
                    {
                        _workItemsInStpQueue = 0;
                    }

                    --_workItemsExecutingInStp;

                    if (_workItemsExecutingInStp < 0)
                    {
                        _workItemsExecutingInStp = 0;
                    }
                }

                // If the work item is not null then enqueue it
                if (null != workItem)
                {
                    workItem.CanceledWorkItemsGroup = _canceledWorkItemsGroup;

                    RegisterToWorkItemCompletion(workItem.GetWorkItemResult());
                    _workItemsQueue.Enqueue(workItem);
                    //_stp.IncrementWorkItemsCount();

                    if ((1 == _workItemsQueue.Count) &&
                        (0 == _workItemsInStpQueue))
                    {
                        _stp.RegisterWorkItemsGroup(this);
                        Trace.WriteLine("WorkItemsGroup " + Name + " is NOT idle");
                        _isIdleWaitHandle.Reset();
                    }
                }

                // If the work items queue of the group is empty than quit
                if (0 == _workItemsQueue.Count)
                {
                    if (0 == _workItemsInStpQueue)
                    {
                        _stp.UnregisterWorkItemsGroup(this);
                        Trace.WriteLine("WorkItemsGroup " + Name + " is idle");
                        _isIdleWaitHandle.Set();
                        _stp.QueueWorkItem(new WorkItemCallback(FireOnIdle));
                    }
                    return;
                }

                if (!_workItemsGroupStartInfo.StartSuspended)
                {
                    if (_workItemsInStpQueue < _concurrency)
                    {
                        var nextWorkItem = _workItemsQueue.Dequeue() as WorkItem;
                        _stp.Enqueue(nextWorkItem, true);
                        ++_workItemsInStpQueue;
                    }
                }
            }
        }
Пример #21
0
 // Token: 0x0600187A RID: 6266
 // RVA: 0x00075414 File Offset: 0x00073614
 private void EnqueueToSTPNextWorkItem(WorkItem workItem_0, bool bool_0)
 {
     lock (this._lock)
     {
         if (bool_0)
         {
             this._workItemsInStpQueue--;
             if (this._workItemsInStpQueue < 0)
             {
                 this._workItemsInStpQueue = 0;
             }
             this._workItemsExecutingInStp--;
             if (this._workItemsExecutingInStp < 0)
             {
                 this._workItemsExecutingInStp = 0;
             }
         }
         if (workItem_0 != null)
         {
             workItem_0.CanceledWorkItemsGroup = this._canceledWorkItemsGroup;
             this.RegisterToWorkItemCompletion(workItem_0.GetWorkItemResult());
             this._workItemsQueue.Enqueue(workItem_0);
             if (1 == this._workItemsQueue.Count && this._workItemsInStpQueue == 0)
             {
                 this._stp.RegisterWorkItemsGroup(this);
                 base.IsIdle = false;
                 this._isIdleWaitHandle.Reset();
             }
         }
         if (this._workItemsQueue.Count == 0)
         {
             if (this._workItemsInStpQueue == 0)
             {
                 this._stp.UnregisterWorkItemsGroup(this);
                 base.IsIdle = true;
                 this._isIdleWaitHandle.Set();
                 if (bool_0 && this._onIdle != null && this._onIdle.GetInvocationList().Length > 0)
                 {
                     this._stp.QueueWorkItem(new WorkItemCallback(this.FireOnIdle));
                 }
             }
         }
         else if (!this._isSuspended && this._workItemsInStpQueue < this._concurrency)
         {
             WorkItem workItem_ = this._workItemsQueue.Dequeue() as WorkItem;
             try
             {
                 this._stp.Enqueue(workItem_);
             }
             catch (ObjectDisposedException ex)
             {
                 ex.GetHashCode();
             }
             this._workItemsInStpQueue++;
         }
     }
 }
Пример #22
0
        private void EnqueueToSTPNextWorkItem(WorkItem workItem, bool decrementWorkItemsInStpQueue)
        {
            lock (_lock)
            {
                // Got here from OnWorkItemCompletedCallback()
                if (decrementWorkItemsInStpQueue)
                {
                    --_workItemsInStpQueue;

                    if (_workItemsInStpQueue < 0)
                    {
                        _workItemsInStpQueue = 0;
                    }

                    --_workItemsExecutingInStp;

                    if (_workItemsExecutingInStp < 0)
                    {
                        _workItemsExecutingInStp = 0;
                    }
                }

                // If the work item is not null then enqueue it
                if (null != workItem)
                {
                    workItem.CanceledWorkItemsGroup = _canceledWorkItemsGroup;

                    RegisterToWorkItemCompletion(workItem.GetWorkItemResult());
                    _workItemsQueue.Enqueue(workItem);
                    //_stp.IncrementWorkItemsCount();

                    if ((1 == _workItemsQueue.Count) &&
                        (0 == _workItemsInStpQueue))
                    {
                        _stp.RegisterWorkItemsGroup(this);
                        Trace.WriteLine("WorkItemsGroup " + Name + " is NOT idle");
                        _isIdleWaitHandle.Reset();
                    }
                }

                // If the work items queue of the group is empty than quit
                if (0 == _workItemsQueue.Count)
                {
                    if (0 == _workItemsInStpQueue)
                    {
                        _stp.UnregisterWorkItemsGroup(this);
                        Trace.WriteLine("WorkItemsGroup " + Name + " is idle");
                        _isIdleWaitHandle.Set();
                        _stp.QueueWorkItem(new WorkItemCallback(FireOnIdle));
                    }
                    return;
                }

                if (!_workItemsGroupStartInfo.StartSuspended)
                {
                    if (_workItemsInStpQueue < _concurrency)
                    {
                        var nextWorkItem = _workItemsQueue.Dequeue() as WorkItem;
                        _stp.Enqueue(nextWorkItem, true);
                        ++_workItemsInStpQueue;
                    }
                }
            }
        }