/// <summary>
        /// Example of how to use the post execute callback
        /// </summary>
        private bool DoTestDefaultPostExecute(CallToPostExecute callToPostExecute, bool answer)
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool();

            WIGStartInfo wigStartInfo = new WIGStartInfo();

            wigStartInfo.CallToPostExecute           = callToPostExecute;
            wigStartInfo.PostExecuteWorkItemCallback = new PostExecuteWorkItemCallback(this.DoSomePostExecuteWork);

            IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue, wigStartInfo);

            bool success = false;

            PostExecuteResult postExecuteResult = new PostExecuteResult();

            IWorkItemResult wir =
                workItemsGroup.QueueWorkItem(
                    new WorkItemCallback(this.DoSomeWork),
                    postExecuteResult);

            if (!wir.IsCompleted)
            {
                int result = (int)wir.GetResult();
                success = (1 == result);
                success = success && (postExecuteResult.wh.WaitOne(1000, true) == answer);
            }

            smartThreadPool.Shutdown();

            return(success);
        }
예제 #2
0
        public WorkItemsGroup(
			SmartThreadPool stp, 
			int concurrency, 
			WIGStartInfo wigStartInfo)
        {
            if (concurrency <= 0)
            {
                throw new ArgumentOutOfRangeException(
                    "concurrency",
            #if !(WindowsCE)
                    concurrency,
            #endif
                    "concurrency must be greater than zero");
            }
            _stp = stp;
            _concurrency = concurrency;
            _workItemsGroupStartInfo = new WIGStartInfo(wigStartInfo).AsReadOnly();
            _workItemsQueue = new PriorityQueue();
            Name = "WorkItemsGroup";

            // The _workItemsInStpQueue gets the number of currently executing work items,
            // because once a work item is executing, it cannot be cancelled.
            _workItemsInStpQueue = _workItemsExecutingInStp;

            _isSuspended = _workItemsGroupStartInfo.StartSuspended;
        }
예제 #3
0
 /// <summary>
 /// Create a new work item
 /// </summary>
 /// <param name="workItemsGroup">The WorkItemsGroup of this workitem</param>
 /// <param name="wigStartInfo">Work item group start information</param>
 /// <param name="callback">A callback to execute</param>
 /// <returns>Returns a work item</returns>
 public static WorkItem CreateWorkItem(
     IWorkItemsGroup workItemsGroup,
     WIGStartInfo wigStartInfo,
     WorkItemCallback callback)
 {
     return(CreateWorkItem(workItemsGroup, wigStartInfo, callback, null));
 }
예제 #4
0
 /// <summary>
 /// Create a new work item
 /// </summary>
 /// <param name="workItemsGroup"></param>
 /// <param name="wigStartInfo">Work item group start 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>
 /// <param name="workItemPriority">The work item priority</param>
 /// <returns>Returns a work item</returns>
 public static WorkItem CreateWorkItem(IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, WorkItemCallback callback, object state, WorkItemPriority workItemPriority)
 {
     ValidateCallback(callback);
     return(new WorkItem(workItemsGroup, new WorkItemInfo {
         UseCallerCallContext = wigStartInfo.UseCallerCallContext, UseCallerHttpContext = wigStartInfo.UseCallerHttpContext, PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback, CallToPostExecute = wigStartInfo.CallToPostExecute, DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects, WorkItemPriority = workItemPriority
     }, callback, state));
 }
예제 #5
0
        /// <summary>
        /// Create a new work item
        /// </summary>
        /// <param name="workItemsGroup">The WorkItemsGroup of this workitem</param>
        /// <param name="wigStartInfo">Work item group start 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</returns>
        public static WorkItem CreateWorkItem(
            IWorkItemsGroup workItemsGroup,
            WIGStartInfo wigStartInfo,
            WorkItemCallback callback,
            object state)
        {
            ValidateCallback(callback);

            WorkItemInfo workItemInfo = new WorkItemInfo();

            workItemInfo.UseCallerCallContext        = wigStartInfo.UseCallerCallContext;
            workItemInfo.UseCallerHttpContext        = wigStartInfo.UseCallerHttpContext;
            workItemInfo.PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback;
            workItemInfo.CallToPostExecute           = wigStartInfo.CallToPostExecute;
            workItemInfo.DisposeOfStateObjects       = wigStartInfo.DisposeOfStateObjects;
            workItemInfo.WorkItemPriority            = wigStartInfo.WorkItemPriority;

            WorkItem workItem = new WorkItem(
                workItemsGroup,
                workItemInfo,
                callback,
                state);

            return(workItem);
        }
예제 #6
0
        /// <summary>
        ///   Create a new work item
        /// </summary>
        /// <param name = "wigStartInfo">Work item group start 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>
        /// <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</returns>
        public static WorkItem CreateWorkItem(
            IWorkItemsGroup workItemsGroup,
            WIGStartInfo wigStartInfo,
            WorkItemCallback callback,
            object state,
            PostExecuteWorkItemCallback postExecuteWorkItemCallback,
            CallToPostExecute callToPostExecute,
            WorkItemPriority workItemPriority)
        {
            ValidateCallback(callback);
            ValidateCallback(postExecuteWorkItemCallback);

            WorkItemInfo workItemInfo = new WorkItemInfo
            {
                UseCallerCallContext        = wigStartInfo.UseCallerCallContext,
                UseCallerHttpContext        = wigStartInfo.UseCallerHttpContext,
                PostExecuteWorkItemCallback = postExecuteWorkItemCallback,
                CallToPostExecute           = callToPostExecute,
                WorkItemPriority            = workItemPriority,
                DisposeOfStateObjects       = wigStartInfo.DisposeOfStateObjects
            };

            WorkItem workItem = new WorkItem(
                workItemsGroup,
                workItemInfo,
                callback,
                state);

            return(workItem);
        }
예제 #7
0
        public void TwoWIGsStartSuspended()
        {
            SmartThreadPool stp = new SmartThreadPool();

            WIGStartInfo wigStartInfo = new WIGStartInfo();

            wigStartInfo.StartSuspended = true;

            IWorkItemsGroup wig1 = stp.CreateWorkItemsGroup(10, wigStartInfo);
            IWorkItemsGroup wig2 = stp.CreateWorkItemsGroup(10, wigStartInfo);

            wig1.QueueWorkItem(new WorkItemCallback(this.DoWork));
            wig2.QueueWorkItem(new WorkItemCallback(this.DoWork));

            Assert.IsFalse(wig1.WaitForIdle(200));
            Assert.IsFalse(wig2.WaitForIdle(200));

            wig1.Start();

            Assert.IsTrue(wig1.WaitForIdle(200));
            Assert.IsFalse(wig2.WaitForIdle(200));

            wig2.Start();

            Assert.IsTrue(wig1.WaitForIdle(0));
            Assert.IsTrue(wig2.WaitForIdle(200));
        }
예제 #8
0
        public WorkItemsGroup(
            SmartThreadPool stp,
            int concurrency,
            WIGStartInfo wigStartInfo)
        {
            if (concurrency <= 0)
            {
                throw new ArgumentOutOfRangeException(
                          "concurrency",
#if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE)
                          concurrency,
#endif
                          "concurrency must be greater than zero");
            }
            _stp                     = stp;
            _concurrency             = concurrency;
            _workItemsGroupStartInfo = new WIGStartInfo(wigStartInfo).AsReadOnly();
            _workItemsQueue          = new PriorityQueue();
            Name                     = "WorkItemsGroup";

            // The _workItemsInStpQueue gets the number of currently executing work items,
            // because once a work item is executing, it cannot be cancelled.
            _workItemsInStpQueue = _workItemsExecutingInStp;

            _isSuspended = _workItemsGroupStartInfo.StartSuspended;
        }
예제 #9
0
 /// <summary>
 ///   Create a new work item
 /// </summary>
 /// <param name = "wigStartInfo">Work item group start information</param>
 /// <param name = "callback">A callback to execute</param>
 /// <returns>Returns a work item</returns>
 public static WorkItem CreateWorkItem(
     IWorkItemsGroup workItemsGroup,
     WIGStartInfo wigStartInfo,
     WorkItemCallback callback)
 {
     return CreateWorkItem(workItemsGroup, wigStartInfo, callback, null);
 }
        public void DontDisposeCallerState()
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool();

            WIGStartInfo wigStartInfo = new WIGStartInfo();

            wigStartInfo.DisposeOfStateObjects = false;

            IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue, wigStartInfo);

            CallerState nonDisposableCallerState = new NonDisposableCallerState();
            CallerState disposableCallerState    = new DisposableCallerState();

            IWorkItemResult wir1 =
                workItemsGroup.QueueWorkItem(
                    new WorkItemCallback(this.DoSomeWork),
                    nonDisposableCallerState);

            IWorkItemResult wir2 =
                workItemsGroup.QueueWorkItem(
                    new WorkItemCallback(this.DoSomeWork),
                    disposableCallerState);

            wir1.GetResult();
            bool success = (1 == nonDisposableCallerState.Value);

            wir2.GetResult();

            success = success && (1 == disposableCallerState.Value);

            smartThreadPool.Shutdown();

            Assert.IsTrue(success);
        }
예제 #11
0
        /// <summary>
        /// Create a new work item
        /// </summary>
        /// <param name="workItemsGroup">The work items group</param>
        /// <param name="wigStartInfo">Work item group start 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>
        /// <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</returns>
        public static WorkItem CreateWorkItem(
            IWorkItemsGroup workItemsGroup,
            WIGStartInfo wigStartInfo,
            WorkItemCallback callback,
            object state,
            PostExecuteWorkItemCallback postExecuteWorkItemCallback,
            CallToPostExecute callToPostExecute,
            WorkItemPriority workItemPriority)
        {
            if (null == wigStartInfo)
            {
                throw new ArgumentNullException("wigStartInfo");
            }

            ValidateCallback(callback);
            ValidateCallback(postExecuteWorkItemCallback);

            WorkItemInfo workItemInfo = new WorkItemInfo();

            workItemInfo.UseCallerCallContext        = wigStartInfo.UseCallerCallContext;
            workItemInfo.UseCallerHttpContext        = wigStartInfo.UseCallerHttpContext;
            workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback;
            workItemInfo.CallToPostExecute           = callToPostExecute;
            workItemInfo.WorkItemPriority            = workItemPriority;
            workItemInfo.DisposeOfStateObjects       = wigStartInfo.DisposeOfStateObjects;

            WorkItem workItem = new WorkItem(
                workItemsGroup,
                workItemInfo,
                callback,
                state);

            return(workItem);
        }
예제 #12
0
        public void STPAndWIGStartSuspended()
        {
            STPStartInfo stpStartInfo = new STPStartInfo();

            stpStartInfo.StartSuspended = true;

            SmartThreadPool stp = new SmartThreadPool(stpStartInfo);

            WIGStartInfo wigStartInfo = new WIGStartInfo();

            wigStartInfo.StartSuspended = true;

            IWorkItemsGroup wig = stp.CreateWorkItemsGroup(10, wigStartInfo);

            wig.QueueWorkItem(new WorkItemCallback(this.DoWork));

            Assert.IsFalse(wig.WaitForIdle(200));

            wig.Start();

            Assert.IsFalse(wig.WaitForIdle(200));

            stp.Start();

            Assert.IsTrue(wig.WaitForIdle(5000), "WIG is not idle");
            Assert.IsTrue(stp.WaitForIdle(5000), "STP is not idle");
        }
예제 #13
0
 public WIGStartInfo(WIGStartInfo wigStartInfo)
 {
     _useCallerCallContext        = wigStartInfo._useCallerCallContext;
     _useCallerHttpContext        = wigStartInfo._useCallerHttpContext;
     _disposeOfStateObjects       = wigStartInfo._disposeOfStateObjects;
     _callToPostExecute           = wigStartInfo._callToPostExecute;
     _postExecuteWorkItemCallback = wigStartInfo._postExecuteWorkItemCallback;
     _startSuspended = wigStartInfo._startSuspended;
 }
        public void Init()
        {
            _stp = new SmartThreadPool();

            WIGStartInfo wigStartInfo = new WIGStartInfo();

            wigStartInfo.FillStateWithArgs = true;
            _wig = _stp.CreateWorkItemsGroup(10, wigStartInfo);
        }
예제 #15
0
 public WIGStartInfo(WIGStartInfo wigStartInfo)
 {
     _useCallerCallContext = wigStartInfo._useCallerCallContext;
     _useCallerHttpContext = wigStartInfo._useCallerHttpContext;
     _disposeOfStateObjects = wigStartInfo._disposeOfStateObjects;
     _callToPostExecute = wigStartInfo._callToPostExecute;
     _postExecuteWorkItemCallback = wigStartInfo._postExecuteWorkItemCallback;
     _startSuspended = wigStartInfo._startSuspended;
 }
예제 #16
0
        public void Init()
        {
            _stp = new STP();

            WIGStartInfo wigStartInfo = new WIGStartInfo
            {
                FillStateWithArgs = true
            };

            _wig = _stp.CreateWorkItemsGroup(10, wigStartInfo);
        }
예제 #17
0
 public WorkItemsGroup(SmartThreadPool stp, int concurrency, WIGStartInfo wigStartInfo)
 {
     if (concurrency <= 0)
     {
         throw new ArgumentOutOfRangeException("concurrency", concurrency, "concurrency must be greater than zero");
     }
     this._stp                     = stp;
     this._concurrency             = concurrency;
     this._workItemsGroupStartInfo = new WIGStartInfo(wigStartInfo);
     this._workItemsQueue          = new PriorityQueue();
     this._workItemsInStpQueue     = this._workItemsExecutingInStp;
 }
예제 #18
0
 // Token: 0x0600185F RID: 6239
 // RVA: 0x00075274 File Offset: 0x00073474
 public static WorkItem CreateWorkItem(IWorkItemsGroup iworkItemsGroup_0, WIGStartInfo wigstartInfo_0, WorkItemCallback workItemCallback_0, object object_0, WorkItemPriority workItemPriority_0)
 {
     WorkItemFactory.ValidateCallback(workItemCallback_0);
     return new WorkItem(iworkItemsGroup_0, new WorkItemInfo
     {
         UseCallerCallContext = wigstartInfo_0.UseCallerCallContext,
         UseCallerHttpContext = wigstartInfo_0.UseCallerHttpContext,
         PostExecuteWorkItemCallback = wigstartInfo_0.PostExecuteWorkItemCallback,
         CallToPostExecute = wigstartInfo_0.CallToPostExecute,
         DisposeOfStateObjects = wigstartInfo_0.DisposeOfStateObjects,
         WorkItemPriority = workItemPriority_0
     }, workItemCallback_0, object_0);
 }
예제 #19
0
        public static WorkItem CreateWorkItem(IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, WorkItemInfo workItemInfo,
                                              WaitCallback callback, object state)
        {
            ValidateCallback(callback);
            ValidateCallback(workItemInfo.PostExecuteWorkItemCallback);

            WorkItem workItem = new WorkItem(
                workItemsGroup,
                new WorkItemInfo(workItemInfo),
                callback,
                state);

            return(workItem);
        }
예제 #20
0
        private void InitSTP()
        {
            STPStartInfo stpStartInfo =
                new STPStartInfo
            {
                StartSuspended   = true,
                MaxWorkerThreads = ((int)spinCon6.Value),
                IdleTimeout      = int.Parse(spinIdleTimeout.Text) * 1000,
            };

            if (_useWindowsPerformanceCounters)
            {
                stpStartInfo.PerformanceCounterInstanceName = "WIG Test SmartThreadPool";
            }
            else
            {
                stpStartInfo.EnableLocalPerformanceCounters = true;
            }

            _smartThreadPool = new SmartThreadPool(stpStartInfo);
            WIGStartInfo wigStartInfo = new WIGStartInfo()
            {
                FillStateWithArgs = true,
            };

            _wig1 = _smartThreadPool.CreateWorkItemsGroup((int)spinCon1.Value, wigStartInfo);
            _wig2 = _smartThreadPool.CreateWorkItemsGroup((int)spinCon2.Value, wigStartInfo);
            _wig3 = _smartThreadPool.CreateWorkItemsGroup((int)spinCon3.Value, wigStartInfo);

            spinCon1.Tag = _wig1;
            spinCon2.Tag = _wig2;
            spinCon3.Tag = _wig3;
            spinCon6.Tag = _smartThreadPool;

            comboWIPriority1.SelectedIndex = 1;
            comboWIPriority2.SelectedIndex = 1;
            comboWIPriority3.SelectedIndex = 1;
            comboWIPriority6.SelectedIndex = 1;

            _wigEntries = new WigEntry[]
            {
                new WigEntry(_wig1, queueUsageControl1, lblStatus1),
                new WigEntry(_wig2, queueUsageControl2, lblStatus2),
                new WigEntry(_wig3, queueUsageControl3, lblStatus3),
            };
            for (int i = 0; i < _lastIndex.Length; i++)
            {
                _lastIndex[i] = 1;
            }
        }
예제 #21
0
        public WorkItemsGroup(
            SmartThreadPool stp, 
            int concurrency, 
            WIGStartInfo wigStartInfo)
        {
            if (concurrency <= 0)
            {
                throw new ArgumentOutOfRangeException("concurrency", concurrency, "concurrency must be greater than zero");
            }
            _stp = stp;
            _concurrency = concurrency;
            _workItemsGroupStartInfo = new WIGStartInfo(wigStartInfo);
            _workItemsQueue = new PriorityQueue();

            // The _workItemsInStpQueue gets the number of currently executing work items,
            // because once a work item is executing, it cannot be cancelled.
            _workItemsInStpQueue = _workItemsExecutingInStp;
        }
예제 #22
0
        public WorkItemsGroup(
            SmartThreadPool stp,
            int concurrency,
            WIGStartInfo wigStartInfo)
        {
            if (concurrency <= 0)
            {
                throw new ArgumentOutOfRangeException("concurrency", concurrency, "concurrency must be greater than zero");
            }
            _stp                     = stp;
            _concurrency             = concurrency;
            _workItemsGroupStartInfo = new WIGStartInfo(wigStartInfo);
            _workItemsQueue          = new PriorityQueue();

            // The _workItemsInStpQueue gets the number of currently executing work items,
            // because once a work item is executing, it cannot be cancelled.
            _workItemsInStpQueue = _workItemsExecutingInStp;
        }
        public void WIGStartSuspended()
        {
            STP stp = new STP();

            WIGStartInfo wigStartInfo = new WIGStartInfo
            {
                StartSuspended = true
            };

            IWorkItemsGroup wig = stp.CreateWorkItemsGroup(10, wigStartInfo);

            wig.QueueWorkItem(new WorkItemCallback(this.DoWork));

            Assert.IsFalse(wig.WaitForIdle(200));

            wig.Start();

            Assert.IsTrue(wig.WaitForIdle(200));
        }
예제 #24
0
        public static WorkItem CreateWorkItem(IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo,
                                              WaitCallback callback, object state)
        {
            ValidateCallback(callback);

            WorkItemInfo workItemInfo = new WorkItemInfo()
            {
                UseCallerCallContext        = wigStartInfo.UseCallerCallContext,
                PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback,
                CallToPostExecute           = wigStartInfo.CallToPostExecute,
                DisposeOfStateObjects       = wigStartInfo.DisposeOfStateObjects,
            };

            WorkItem workItem = new WorkItem(
                workItemsGroup,
                workItemInfo,
                callback,
                state);

            return(workItem);
        }
예제 #25
0
        /// <summary>
        /// Create a new work item
        /// </summary>
        /// <param name="workItemsGroup"></param>
        /// <param name="wigStartInfo">Work item group start 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</returns>
        public static WorkItem CreateWorkItem(
			IWorkItemsGroup workItemsGroup,
			WIGStartInfo wigStartInfo,
			WorkItemCallback callback, 
			object state)
        {
            ValidateCallback(callback);

            WorkItemInfo workItemInfo = new WorkItemInfo();
            workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
            workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
            workItemInfo.PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback;
            workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute;
            workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;

            WorkItem workItem = new WorkItem(
                workItemsGroup,
                workItemInfo,
                callback,
                state);
            return workItem;
        }
예제 #26
0
        public WorkItemsGroup(
            CThreadPool ctp,
            int concurrency,
            WIGStartInfo wigStartInfo)
        {
            if (concurrency <= 0)
            {
                throw new ArgumentOutOfRangeException(
                          "concurrency",
                          concurrency,
                          "concurrency must be greater than zero");
            }
            _ctp                     = ctp;
            _concurrency             = concurrency;
            _workItemsGroupStartInfo = new WIGStartInfo(wigStartInfo).AsReadOnly();
            _workItemsQueue          = new PriorityQueue();
            Name                     = "WorkItemsGroup";

            // The _workItemsInStpQueue gets the number of currently executing work items,
            // because once a work item is executing, it cannot be cancelled.
            _workItemsInCtpQueue = _workItemsExecutingInCtp;

            _isSuspended = _workItemsGroupStartInfo.StartSuspended;
        }
예제 #27
0
        public void DoWork(object [] states)
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool();

            WIGStartInfo wigStartInfo = new WIGStartInfo();

            wigStartInfo.StartSuspended = true;

            IWorkItemsGroup wig = smartThreadPool.CreateWorkItemsGroup(1, wigStartInfo);

            foreach (object state in states)
            {
                wig.QueueWorkItem(new
                                  WorkItemCallback(this.DoSomeWork), state);
            }

            // Start working on the work items in the work items group queue
            wig.Start();

            // Wait for the completion of all work items
            wig.WaitForIdle();

            smartThreadPool.Shutdown();
        }
예제 #28
0
        /// <summary>
        /// Create a new work item
        /// </summary>
        /// <param name="workItemsGroup">The work items group</param>
        /// <param name="wigStartInfo">Work item group start information</param>
        /// <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</returns>
        public static WorkItem CreateWorkItem(
            IWorkItemsGroup workItemsGroup,
            WIGStartInfo wigStartInfo,
            WorkItemInfo workItemInfo,
            WorkItemCallback callback,
            object state)
        {
            if (null == workItemInfo)
            {
                throw new ArgumentNullException("workItemInfo");
            }

            ValidateCallback(callback);
            ValidateCallback(workItemInfo.PostExecuteWorkItemCallback);


            WorkItem workItem = new WorkItem(
                workItemsGroup,
                new WorkItemInfo(workItemInfo),
                callback,
                state);

            return(workItem);
        }
        public void DisposeCallerState()
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool();

            WIGStartInfo wigStartInfo = new WIGStartInfo();

            wigStartInfo.DisposeOfStateObjects = true;

            IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue, wigStartInfo);

            CallerState nonDisposableCallerState = new NonDisposableCallerState();
            CallerState disposableCallerState    = new DisposableCallerState();

            IWorkItemResult wir1 =
                workItemsGroup.QueueWorkItem(
                    new WorkItemCallback(this.DoSomeWork),
                    nonDisposableCallerState);

            IWorkItemResult wir2 =
                workItemsGroup.QueueWorkItem(
                    new WorkItemCallback(this.DoSomeWork),
                    disposableCallerState);

            wir1.GetResult();
            Assert.AreEqual(1, nonDisposableCallerState.Value);

            wir2.GetResult();

            // Wait a little bit for the working thread to call dispose on the
            // work item's state.
            workItemsGroup.WaitForIdle();

            Assert.AreEqual(2, disposableCallerState.Value);

            smartThreadPool.Shutdown();
        }
예제 #30
0
        /// <summary>
        ///   Create a new work item
        /// </summary>
        /// <param name = "wigStartInfo">Work item group start 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>
        /// <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</returns>
        public static WorkItem CreateWorkItem(
            IWorkItemsGroup workItemsGroup,
            WIGStartInfo wigStartInfo,
            WorkItemCallback callback,
            object state,
            PostExecuteWorkItemCallback postExecuteWorkItemCallback,
            CallToPostExecute callToPostExecute,
            WorkItemPriority workItemPriority)
        {
            ValidateCallback(callback);
            ValidateCallback(postExecuteWorkItemCallback);

            WorkItemInfo workItemInfo = new WorkItemInfo
                                            {
                                                UseCallerCallContext = wigStartInfo.UseCallerCallContext,
                                                UseCallerHttpContext = wigStartInfo.UseCallerHttpContext,
                                                PostExecuteWorkItemCallback = postExecuteWorkItemCallback,
                                                CallToPostExecute = callToPostExecute,
                                                WorkItemPriority = workItemPriority,
                                                DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects
                                            };

            WorkItem workItem = new WorkItem(
                workItemsGroup,
                workItemInfo,
                callback,
                state);

            return workItem;
        }
예제 #31
0
 // Token: 0x0600185D RID: 6237
 // RVA: 0x00014E50 File Offset: 0x00013050
 public static WorkItem CreateWorkItem(IWorkItemsGroup iworkItemsGroup_0, WIGStartInfo wigstartInfo_0, WorkItemCallback workItemCallback_0, WorkItemPriority workItemPriority_0)
 {
     return WorkItemFactory.CreateWorkItem(iworkItemsGroup_0, wigstartInfo_0, workItemCallback_0, null, workItemPriority_0);
 }
예제 #32
0
        /// <summary>
        ///   Create a new work item
        /// </summary>
        /// <param name = "wigStartInfo">Work item group start information</param>
        /// <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</returns>
        public static WorkItem CreateWorkItem(
            IWorkItemsGroup workItemsGroup,
            WIGStartInfo wigStartInfo,
            WorkItemInfo workItemInfo,
            WorkItemCallback callback,
            object state)
        {
            ValidateCallback(callback);
            ValidateCallback(workItemInfo.PostExecuteWorkItemCallback);

            WorkItem workItem = new WorkItem(
                workItemsGroup,
                new WorkItemInfo(workItemInfo),
                callback,
                state);

            return workItem;
        }
예제 #33
0
 public static WorkItem CreateWorkItem(IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, WorkItemCallback callback, WorkItemPriority workItemPriority)
 {
     return(WorkItemFactory.CreateWorkItem(workItemsGroup, wigStartInfo, callback, null, workItemPriority));
 }
예제 #34
0
 public static WorkItem CreateWorkItem(IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, WorkItemInfo workItemInfo, WorkItemCallback callback, object state)
 {
     WorkItemFactory.ValidateCallback(callback);
     WorkItemFactory.ValidateCallback(workItemInfo.PostExecuteWorkItemCallback);
     return(new WorkItem(workItemsGroup, new WorkItemInfo(workItemInfo), callback, state));
 }