GetWorkItemResult() private method

Returns the work item result
private GetWorkItemResult ( ) : IWorkItemResult
return IWorkItemResult
Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 7
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>
        /// <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()));
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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()));
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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()));
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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;
                    }
                }
            }
        }
Ejemplo n.º 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;
                    }
                }
            }
        }
Ejemplo n.º 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;
                    }
                }
            }
        }
Ejemplo n.º 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++;
         }
     }
 }
Ejemplo n.º 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;
                    }
                }
            }
        }