• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Threading.STPStartInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Amib.Threading.STPStartInfo的典型用法代码示例。如果您正苦于以下问题:C# STPStartInfo类的具体用法?C# STPStartInfo怎么用?C# STPStartInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



STPStartInfo类属于Amib.Threading命名空间,在下文中一共展示了STPStartInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: STPAndWIGStartSuspended

        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");
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:25,代码来源:TestStartSuspended.cs


示例2: DisposeCallerState

        public void DisposeCallerState() 
        { 
            STPStartInfo stpStartInfo = new STPStartInfo();
            stpStartInfo.DisposeOfStateObjects = true;
     
            SmartThreadPool smartThreadPool = new SmartThreadPool(stpStartInfo);

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

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

            IWorkItemResult wir2 = 
                smartThreadPool.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.
			smartThreadPool.WaitForIdle();

			Assert.AreEqual(2, disposableCallerState.Value);

            smartThreadPool.Shutdown();
        } 
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:33,代码来源:TestStateDispose.cs


示例3: CancelCanceledWorkItem

        public void CancelCanceledWorkItem()
        {
            STPStartInfo stpStartInfo = new STPStartInfo();
            stpStartInfo.StartSuspended = true;

            SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
            IWorkItemResult wir = stp.QueueWorkItem(state => null);

            int counter = 0;

            wir.Cancel();

            try
            {
                wir.GetResult();
            }
            catch (WorkItemCancelException ce)
            {
                ce.GetHashCode();
                ++counter;
            }

            Assert.AreEqual(counter, 1);

            wir.Cancel();

            try
            {
                wir.GetResult();
            }
            finally
            {
                stp.Shutdown();
            }
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:35,代码来源:TestCancel.cs


示例4: STPStartInfo

 public STPStartInfo(STPStartInfo stpStartInfo)
     : base(stpStartInfo)
 {
     _idleTimeout = stpStartInfo.IdleTimeout;
     _minWorkerThreads = stpStartInfo.MinWorkerThreads;
     _maxWorkerThreads = stpStartInfo.MaxWorkerThreads;
     _threadPriority = stpStartInfo.ThreadPriority;
     _performanceCounterInstanceName = stpStartInfo.PerformanceCounterInstanceName;
 }
开发者ID:vls,项目名称:hp2p,代码行数:9,代码来源:STPStartInfo.cs


示例5: STPStartInfo

 public STPStartInfo(STPStartInfo stpStartInfo) : base(stpStartInfo)
 {
     _idleTimeout = stpStartInfo._idleTimeout;
     _minWorkerThreads = stpStartInfo._minWorkerThreads;
     _maxWorkerThreads = stpStartInfo._maxWorkerThreads;
     _threadPriority = stpStartInfo._threadPriority;
     _pcInstanceName = stpStartInfo._pcInstanceName;
     _stackSize = stpStartInfo._stackSize;
 }
开发者ID:nathanmarck,项目名称:Aurora-Sim,代码行数:9,代码来源:STPStartInfo.cs


示例6: CheckSinglePriority

        private void CheckSinglePriority(ThreadPriority threadPriority)
        {
            STPStartInfo stpStartInfo = new STPStartInfo();
            stpStartInfo.ThreadPriority = threadPriority;

            SmartThreadPool stp = new SmartThreadPool(stpStartInfo);

            IWorkItemResult wir = stp.QueueWorkItem(new WorkItemCallback(GetThreadPriority));
            ThreadPriority currentThreadPriority = (ThreadPriority)wir.GetResult();

            Assert.AreEqual(threadPriority, currentThreadPriority);
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:12,代码来源:TestThreadPriority.cs


示例7: STPStartInfo

 public STPStartInfo(STPStartInfo stpStartInfo)
     : base(stpStartInfo)
 {
     _idleTimeout = stpStartInfo.IdleTimeout;
     _minWorkerThreads = stpStartInfo.MinWorkerThreads;
     _maxWorkerThreads = stpStartInfo.MaxWorkerThreads;
     _threadPriority = stpStartInfo.ThreadPriority;
     _performanceCounterInstanceName = stpStartInfo.PerformanceCounterInstanceName;
     _enableLocalPerformanceCounters = stpStartInfo._enableLocalPerformanceCounters;
     _threadPoolName = stpStartInfo._threadPoolName;
     _areThreadsBackground = stpStartInfo.AreThreadsBackground;
     ThreadApartmentState = stpStartInfo.ThreadApartmentState;
 }
开发者ID:MattHoneycutt,项目名称:stp,代码行数:13,代码来源:STPStartInfo.cs


示例8: QueueWorkItem_WhenMaxIsNull_Queues

        public void QueueWorkItem_WhenMaxIsNull_Queues()
        {
            var info = new STPStartInfo
            {
                MaxQueueLength = null,
            };
            var pool = new SmartThreadPool(info);
            pool.Start();
            var workItem = pool.QueueWorkItem<object>(ReturnNull);

            // If rejected, an exception would have been thrown instead.
            Assert.IsTrue(workItem.GetResult() == null);
        }
开发者ID:amibar,项目名称:SmartThreadPool,代码行数:13,代码来源:TestMaxQueueLength.cs


示例9: STPStartInfo

 // Token: 0x06001842 RID: 6210
 // RVA: 0x00074F58 File Offset: 0x00073158
 public STPStartInfo(STPStartInfo stpstartInfo_0)
     : base(stpstartInfo_0)
 {
     this._idleTimeout = stpstartInfo_0.IdleTimeout;
     this._minWorkerThreads = stpstartInfo_0.MinWorkerThreads;
     this._maxWorkerThreads = stpstartInfo_0.MaxWorkerThreads;
     this._threadPriority = stpstartInfo_0.ThreadPriority;
     this._performanceCounterInstanceName = stpstartInfo_0.PerformanceCounterInstanceName;
     this._enableLocalPerformanceCounters = stpstartInfo_0._enableLocalPerformanceCounters;
     this._threadPoolName = stpstartInfo_0._threadPoolName;
     this._areThreadsBackground = stpstartInfo_0.AreThreadsBackground;
     this._apartmentState = stpstartInfo_0._apartmentState;
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:15,代码来源:STPStartInfo.cs


示例10: Init

        public static bool Init(bool useSmartThredPool)
        {
            if (Pool == null)
            {
                STPStartInfo param = new STPStartInfo();
                param.MinWorkerThreads = 2;
                param.MaxWorkerThreads = 50;
                param.ThreadPoolName = "LibOpenMetaverse Main ThreadPool";
                param.AreThreadsBackground = true;

                Pool = new SmartThreadPool(param);
            }
            return true;
        }
开发者ID:jakzodiac,项目名称:libopenmetaverse,代码行数:14,代码来源:WorkPool.cs


示例11: InitSTP

        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;
            }
        }
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:49,代码来源:Form1.cs


示例12: Worker

        static Worker()
        {
            STPStartInfo stpStartInfo = new STPStartInfo();

            stpStartInfo.IdleTimeout = Worker.IdleTimeoutConfig * 1000;
            stpStartInfo.PerformanceCounterInstanceName = Worker.instanceName;
            stpStartInfo.MaxWorkerThreads = 300;

            Worker.smartThreadPool = new SmartThreadPool(stpStartInfo);

            _getActiveThreads = () => (long)smartThreadPool.ActiveThreads;
            _getInUseThreads = () => (long)smartThreadPool.InUseThreads;
            _getQueuedWorkItems = () => (long)smartThreadPool.CurrentWorkItemsCount;
            _getCompletedWorkItems = () => (long)smartThreadPool.WorkItemsProcessed;
        }
开发者ID:nambok,项目名称:twitterRT,代码行数:15,代码来源:Worker.cs


示例13: CheckIsBackground

        private static void CheckIsBackground(bool isBackground)
	    {
	        STPStartInfo stpStartInfo = new STPStartInfo();
	        stpStartInfo.AreThreadsBackground = isBackground;

	        SmartThreadPool stp = new SmartThreadPool(stpStartInfo);

            IWorkItemResult<bool> wir = stp.QueueWorkItem(() => GetCurrentThreadIsBackground());

	        bool resultIsBackground = wir.GetResult();

	        stp.WaitForIdle();

            Assert.AreEqual(isBackground, resultIsBackground);
	    }
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:15,代码来源:TestThreadIsBackground.cs


示例14: StartSuspended

        public void StartSuspended()
        {
            STPStartInfo stpStartInfo = new STPStartInfo();
            stpStartInfo.StartSuspended = true;

            SmartThreadPool stp = new SmartThreadPool(stpStartInfo);

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

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

            stp.Start();

            Assert.IsTrue(stp.WaitForIdle(200));
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:15,代码来源:TestStartSuspended.cs


示例15: CheckApartmentState

	    private static void CheckApartmentState(ApartmentState requestApartmentState)
	    {
	        STPStartInfo stpStartInfo = new STPStartInfo();
            stpStartInfo.ApartmentState = requestApartmentState;

	        SmartThreadPool stp = new SmartThreadPool(stpStartInfo);

	        IWorkItemResult<ApartmentState> wir = stp.QueueWorkItem(() => GetCurrentThreadApartmentState());

	        ApartmentState resultApartmentState = wir.GetResult();

	        stp.WaitForIdle();

	        Assert.AreEqual(requestApartmentState, resultApartmentState);
	    }
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:15,代码来源:TestThreadApartmentState.cs


示例16: STPStartInfo

	    public STPStartInfo(STPStartInfo stpStartInfo)
            : base(stpStartInfo)
        {
            _idleTimeout = stpStartInfo.IdleTimeout;
            _minWorkerThreads = stpStartInfo.MinWorkerThreads;
            _maxWorkerThreads = stpStartInfo.MaxWorkerThreads;
#if !(WINDOWS_PHONE)
            _threadPriority = stpStartInfo.ThreadPriority;
#endif
            _performanceCounterInstanceName = stpStartInfo.PerformanceCounterInstanceName;
            _enableLocalPerformanceCounters = stpStartInfo._enableLocalPerformanceCounters;
            _threadPoolName = stpStartInfo._threadPoolName;
            _areThreadsBackground = stpStartInfo.AreThreadsBackground;
#if !(_SILVERLIGHT) && !(WINDOWS_PHONE)
            _apartmentState = stpStartInfo._apartmentState;
#endif
        }
开发者ID:CassieEllen,项目名称:opensim,代码行数:17,代码来源:STPStartInfo.cs


示例17: QueueWorkItem_WhenBiggerMaxIsSet_ThrowsExceptionWhenHit

        public void QueueWorkItem_WhenBiggerMaxIsSet_ThrowsExceptionWhenHit()
        {
            Assert.Throws<QueueRejectedException>(() =>
            {
                var info = new STPStartInfo
                {
                    MaxQueueLength = 5,
                    MinWorkerThreads = 5,
                    MaxWorkerThreads = 10,
                };
                var pool = new SmartThreadPool(info);
                pool.Start();

                try
                {
                    // Pool starts with 5 available waiters.

                    pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.
                    pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.
                    pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.
                    pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.
                    pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.

                    pool.QueueWorkItem(SleepForOneSecond); // New thread created, takes work item. Not queued.
                    pool.QueueWorkItem(SleepForOneSecond); // New thread created, takes work item. Not queued.
                    pool.QueueWorkItem(SleepForOneSecond); // New thread created, takes work item. Not queued.
                    pool.QueueWorkItem(SleepForOneSecond); // New thread created, takes work item. Not queued.
                    pool.QueueWorkItem(SleepForOneSecond); // New thread created, takes work item. Not queued.

                    pool.QueueWorkItem(SleepForOneSecond); // No waiters available. Queued.
                    pool.QueueWorkItem(SleepForOneSecond); // No waiters available. Queued.
                    pool.QueueWorkItem(SleepForOneSecond); // No waiters available. Queued.
                    pool.QueueWorkItem(SleepForOneSecond); // No waiters available. Queued.
                    pool.QueueWorkItem(SleepForOneSecond); // No waiters available. Queued.
                }
                catch (QueueRejectedException e)
                {
                    throw new Exception("Caught QueueRejectedException too early: ", e);
                }

                // All threads are busy, and queue is at its max. Throws.
                pool.QueueWorkItem(SleepForOneSecond);
            });
        }
开发者ID:amibar,项目名称:SmartThreadPool,代码行数:44,代码来源:TestMaxQueueLength.cs


示例18: Concurrency

		private void Concurrency(
			int concurrencyPerWig,
			int wigsCount,
			int workItemsCount)
		{
			Console.WriteLine(
				"Testing : concurrencyPerWig = {0}, wigsCount = {1}, workItemsCount = {2}",
				concurrencyPerWig,
				wigsCount,
				workItemsCount);

			_success = true;
			_concurrencyPerWig = concurrencyPerWig;
			_randGen = new Random(0);

			STPStartInfo stpStartInfo = new STPStartInfo();
			stpStartInfo.StartSuspended = true;

			SmartThreadPool stp = new SmartThreadPool(stpStartInfo);

			_concurrentOps = new int[wigsCount];

			IWorkItemsGroup [] wigs = new IWorkItemsGroup[wigsCount];

			for(int i = 0; i < wigs.Length; ++i)
			{
				wigs[i] = stp.CreateWorkItemsGroup(_concurrencyPerWig);
				for(int j = 0; j < workItemsCount; ++j)
				{
					wigs[i].QueueWorkItem(new WorkItemCallback(this.DoWork), i);
				}

				wigs[i].Start();
			}

			stp.Start();

			stp.WaitForIdle();

			Assert.IsTrue(_success);

			stp.Shutdown();
		}
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:43,代码来源:TestWIGConcurrency.cs


示例19: NotTestThreadsMaxStackSize

        // Can't run this test, StackOverflowException crashes the application and can't be catched and ignored
        //[Test]
        public void NotTestThreadsMaxStackSize()
        {
            STPStartInfo stpStartInfo = new STPStartInfo()
            {
                MaxStackSize = 64 * 1024,
            };

            SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
            stp.Start();

            IWorkItemResult<bool> wir = stp.QueueWorkItem(() => AllocateBufferOnStack(10 * 1024));

            bool result = wir.GetResult();
            Assert.IsTrue(result);

            wir = stp.QueueWorkItem(() => AllocateBufferOnStack(1000 * 1024));

            result = wir.GetResult();
            Assert.IsFalse(result);
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:22,代码来源:TestThreadsCreate.cs


示例20: Start_Click

        private void Start_Click(object sender, RoutedEventArgs e)
        {
            btnStart.IsEnabled = false;
            btnStop.IsEnabled = true;

            UpdateControls(true);
            workItemsCompleted = 0;
            workItemsGenerated = 0;

            STPStartInfo stpStartInfo = new STPStartInfo();
            stpStartInfo.IdleTimeout = _spinIdleTimeout.Value * 1000;
            stpStartInfo.MaxWorkerThreads = _spinMaxThreads.Value;
            stpStartInfo.MinWorkerThreads = _spinMinThreads.Value;
            stpStartInfo.EnableLocalPerformanceCounters = true;

            _stp = new SmartThreadPool(stpStartInfo);

            workItemsProducerThread = new Thread(WorkItemsProducer) {IsBackground = true};
            workItemsProducerThread.Start();
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:20,代码来源:Page.xaml.cs



注:本文中的Amib.Threading.STPStartInfo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Threading.SmartThreadPool类代码示例发布时间:2022-05-24
下一篇:
C# StorageGateway.AmazonStorageGatewayConfig类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap