Summary description for WIGStartInfo.
        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");
        }
        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));
        }
        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();
        } 
        public void Init()
        {
            _stp = new SmartThreadPool();

            WIGStartInfo wigStartInfo = new WIGStartInfo();
            wigStartInfo.FillStateWithArgs = true;
            _wig = _stp.CreateWorkItemsGroup(10, wigStartInfo);
        }
Example #5
0
 public WIGStartInfo(WIGStartInfo wigStartInfo)
 {
     _useCallerCallContext        = wigStartInfo.UseCallerCallContext;
     _disposeOfStateObjects       = wigStartInfo.DisposeOfStateObjects;
     _callToPostExecute           = wigStartInfo.CallToPostExecute;
     _postExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback;
     _startSuspended    = wigStartInfo.StartSuspended;
     _fillStateWithArgs = wigStartInfo.FillStateWithArgs;
 }
Example #6
0
 public WIGStartInfo(WIGStartInfo wigStartInfo)
 {
     _useCallerCallContext = wigStartInfo.UseCallerCallContext;
     _useCallerHttpContext = wigStartInfo.UseCallerHttpContext;
     _disposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
     _callToPostExecute = wigStartInfo.CallToPostExecute;
     _postExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback;
     _workItemPriority = wigStartInfo.WorkItemPriority;
     _startSuspended = wigStartInfo.StartSuspended;
     _fillStateWithArgs = wigStartInfo.FillStateWithArgs;
 }
 public WIGStartInfo(WIGStartInfo wigStartInfo)
 {
     _useCallerCallContext        = wigStartInfo._useCallerCallContext;
     _useCallerHttpContext        = wigStartInfo._useCallerHttpContext;
     _disposeOfStateObjects       = wigStartInfo._disposeOfStateObjects;
     _callToPostExecute           = wigStartInfo._callToPostExecute;
     _postExecuteWorkItemCallback = wigStartInfo._postExecuteWorkItemCallback;
     _workItemPriority            = wigStartInfo._workItemPriority;
     _startSuspended    = wigStartInfo._startSuspended;
     _fillStateWithArgs = wigStartInfo._fillStateWithArgs;
 }
Example #8
0
 // Token: 0x06001837 RID: 6199
 // RVA: 0x00074E5C File Offset: 0x0007305C
 public WIGStartInfo(WIGStartInfo wigstartInfo_0)
 {
     this._useCallerCallContext = wigstartInfo_0.UseCallerCallContext;
     this._useCallerHttpContext = wigstartInfo_0.UseCallerHttpContext;
     this._disposeOfStateObjects = wigstartInfo_0.DisposeOfStateObjects;
     this._callToPostExecute = wigstartInfo_0.CallToPostExecute;
     this._postExecuteWorkItemCallback = wigstartInfo_0.PostExecuteWorkItemCallback;
     this._workItemPriority = wigstartInfo_0.WorkItemPriority;
     this._startSuspended = wigstartInfo_0.StartSuspended;
     this._fillStateWithArgs = wigstartInfo_0.FillStateWithArgs;
 }
		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();
		} 
 public IWorkItemsGroup CreateWorkItemsGroup(int concurrency, WIGStartInfo wigStartInfo)
 {
     IWorkItemsGroup workItemsGroup = new WorkItemsGroup(this, concurrency, wigStartInfo);
     return workItemsGroup;
 }
 public WIGStartInfoRO(WIGStartInfo wigStartInfoRO)
 {
     _wigStartInfoRO = wigStartInfoRO;
 }
        /// <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;
        }
Example #13
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;
            }
        }
Example #14
0
        /// <summary>
        /// Adds a new work group.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="concurrencyLevel">The concurrency level.</param>
        /// <param name="maxQueueSize">Maximum size of the queue. Work groups have a queue that is separate per queue, and is not shared with non work group items</param>
        /// <returns></returns>
        /// <exception cref="DotNetWorkQueueException">Start must be called on the scheduler before adding work groups</exception>
        public override IWorkGroup AddWorkGroup(string name, int concurrencyLevel, int maxQueueSize)
        {
            ThrowIfDisposed();

            if (_smartThreadPool == null)
                throw new DotNetWorkQueueException("Start must be called on the scheduler before adding work groups");

            var group = new WorkGroup(name, concurrencyLevel, maxQueueSize);
            if (_groups.ContainsKey(group)) return _groups[group].GroupInfo;

            var startInfo = new WIGStartInfo
            {
                PostExecuteWorkItemCallback = PostExecuteWorkItemCallback
            };
            var groupWithItem = new WorkGroupWithItem(group, _smartThreadPool.CreateWorkItemsGroup(concurrencyLevel, startInfo), _metrics.Counter(
                $"work group {name}", Units.Items));
            _groups.TryAdd(group, groupWithItem);
            return groupWithItem.GroupInfo;
        }
        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);
        }