当前位置: 首页>>代码示例>>C#>>正文


C# SmartThreadPool.Shutdown方法代码示例

本文整理汇总了C#中Amib.Threading.SmartThreadPool.Shutdown方法的典型用法代码示例。如果您正苦于以下问题:C# SmartThreadPool.Shutdown方法的具体用法?C# SmartThreadPool.Shutdown怎么用?C# SmartThreadPool.Shutdown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Amib.Threading.SmartThreadPool的用法示例。


在下文中一共展示了SmartThreadPool.Shutdown方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoWork

		public void DoWork() 
		{ 
			SmartThreadPool smartThreadPool = new SmartThreadPool();

			DivArgs divArgs = new DivArgs();
			divArgs.x = 10;
			divArgs.y = 0;

			IWorkItemResult wir = 
				smartThreadPool.QueueWorkItem(new 
					WorkItemCallback(this.DoDiv), divArgs);

			Exception e;
			object obj = wir.GetResult(out e);
			// e contains the expetion that DoDiv threw
			if(null == e)
			{
				int result = (int)obj;
			}
			else
			{
				// Do something with the exception
			}

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

示例2: calculateLabel

        private static int calculateLabel(Individual[] weights)
        {
            Individual[] reversedWeights = { weights[1], weights[0] };
            weights[1].ResetScores();
            weights[0].ResetScores();
            SmartThreadPool smtp = new SmartThreadPool();
            for (int index = 0; index < numberOfGames; index++)
            {

                if (index % 2 == 1)
                {
                    smtp.QueueWorkItem(new WorkItemCallback(threadProc), weights);
                }
                else
                {
                    smtp.QueueWorkItem(new WorkItemCallback(threadProc), reversedWeights);
                }

            }
            smtp.WaitForIdle();
            smtp.Shutdown();
            //double strengthRatio = ((double)weights[0].Wins + (double)weights[0].Draws / 2) / numberOfGames;
            //return strengthRatio > 0.5 ? 1 : -1;
            return weights[0].Wins + 1/2 * weights[0].Draws;
        }
开发者ID:KamikazeBVB,项目名称:Checkers-and-Reversi,代码行数:25,代码来源:Program.cs

示例3: TestJoin

        public void TestJoin()
        {
            SmartThreadPool stp = new SmartThreadPool();

            SafeCounter sc = new SafeCounter();

            stp.Join(
                sc.Increment,
                sc.Increment,
                sc.Increment);

            Assert.AreEqual(3, sc.Counter);

            for (int j = 0; j < 10; j++)
            {
                sc.Reset();

                Action[] actions = new Action[1000];
                for (int i = 0; i < actions.Length; i++)
                {
                    actions[i] = sc.Increment;
                }

                stp.Join(actions);

                Assert.AreEqual(actions.Length, sc.Counter);
            }

            stp.Shutdown();
        }
开发者ID:MattHoneycutt,项目名称:stp,代码行数:30,代码来源:TestParallelMethods.cs

示例4: TestMaxThreadsChange

        public void TestMaxThreadsChange()
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool(1 * 1000, 1, 0);

            for (int i = 0; i < 100; ++i)
            {
                smartThreadPool.QueueWorkItem(
                    new WorkItemCallback(this.DoSomeWork),
                    null);
            }

            bool success = WaitForMaxThreadsValue(smartThreadPool, 1, 1 * 1000);
            Assert.IsTrue(success);

            smartThreadPool.MaxThreads = 5;
            success = WaitForMaxThreadsValue(smartThreadPool, 5, 2 * 1000);
            Assert.IsTrue(success);

            smartThreadPool.MaxThreads = 25;
            success = WaitForMaxThreadsValue(smartThreadPool, 25, 4 * 1000);
            Assert.IsTrue(success);

            smartThreadPool.MaxThreads = 10;
            success = WaitForMaxThreadsValue(smartThreadPool, 10, 10 * 1000);
            Assert.IsTrue(success);

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

示例5: TestWIGConcurrencyChange

        public void TestWIGConcurrencyChange()
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool(10 * 1000, 25, 0);

            IWorkItemsGroup wig = smartThreadPool.CreateWorkItemsGroup(smartThreadPool.MaxThreads);
            bool success = false;

            for (int i = 0; i < 100; ++i)
            {
                wig.QueueWorkItem(new WorkItemCallback(this.DoSomeLongWork), null);
            }

            wig.Concurrency = 1;
            success = WaitForWIGThreadsInUse(wig, 1, 1 * 1000);
            Assert.IsTrue(success);

            wig.Concurrency = 5;
            success = WaitForWIGThreadsInUse(wig, 5, 2 * 1000);
            Assert.IsTrue(success);

            wig.Concurrency = 25;
            success = WaitForWIGThreadsInUse(wig, 25, 4 * 1000);
            Assert.IsTrue(success);

            wig.Concurrency = 10;
            success = WaitForWIGThreadsInUse(wig, 10, 10 * 1000);
            Assert.IsTrue(success);

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

示例6: WaitForIdleOnSTPThreadForAnotherWorkItemsGroup

		public void WaitForIdleOnSTPThreadForAnotherWorkItemsGroup()
		{ 
			SmartThreadPool smartThreadPool = new SmartThreadPool(10*1000, 25, 0);
			IWorkItemsGroup workItemsGroup1 = smartThreadPool.CreateWorkItemsGroup(int.MaxValue);
			IWorkItemsGroup workItemsGroup2 = smartThreadPool.CreateWorkItemsGroup(int.MaxValue);

			workItemsGroup1.QueueWorkItem(
				new WorkItemCallback(this.DoSomeWork), 
				1000);

			workItemsGroup1.QueueWorkItem(
				new WorkItemCallback(this.DoSomeWork), 
				1000);

			IWorkItemResult wir = workItemsGroup2.QueueWorkItem(
				new WorkItemCallback(this.DoWaitForIdle), 
				workItemsGroup1);

			Exception e;
			wir.GetResult(out e);

			smartThreadPool.Shutdown();

			Assert.IsNull(e);
		} 
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:25,代码来源:TestWIGWaitForIdle.cs

示例7: GoodCallback

        public void GoodCallback()
        {
            SmartThreadPool stp = new SmartThreadPool();

            stp.QueueWorkItem(new WorkItemCallback(DoWork));

            stp.WaitForIdle();

            stp.Shutdown();
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:10,代码来源:TestChainedDelegates.cs

示例8: GoodCallback

        public void GoodCallback()
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool();
            IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue);

            workItemsGroup.QueueWorkItem(new WorkItemCallback(DoWork));

            workItemsGroup.WaitForIdle();

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

示例9: ChainedDelegatesCallback

        public void ChainedDelegatesCallback()
        {
            SmartThreadPool stp = new SmartThreadPool();

            WorkItemCallback workItemCallback = new WorkItemCallback(DoWork);
            workItemCallback += new WorkItemCallback(DoWork);

            stp.QueueWorkItem(workItemCallback);

            stp.WaitForIdle();

            stp.Shutdown();
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:13,代码来源:TestChainedDelegates.cs

示例10: GoodPostExecute

        public void GoodPostExecute()
        {
            SmartThreadPool stp = new SmartThreadPool();

            stp.QueueWorkItem(
                new WorkItemCallback(DoWork),
                null,
                new PostExecuteWorkItemCallback(DoPostExecute));

            stp.WaitForIdle();

            stp.Shutdown();
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:13,代码来源:TestChainedDelegates.cs

示例11: DoWork

        public void DoWork(int[] numbers)
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool();

            // Queue the work item
            IWorkItemResult<double> wir = smartThreadPool.QueueWorkItem(new Func<int[], double>(CalcAverage), numbers);

            // Do some other work here

            // Get the result of the operation
            double average = wir.Result;

            smartThreadPool.Shutdown();
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:14,代码来源:SimpleExample.cs

示例12: ChainedDelegatesCallback

        public void ChainedDelegatesCallback()
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool();
            IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue);

            WorkItemCallback workItemCallback = new WorkItemCallback(DoWork);
            workItemCallback += new WorkItemCallback(DoWork);

            workItemsGroup.QueueWorkItem(workItemCallback);

            workItemsGroup.WaitForIdle();

            smartThreadPool.Shutdown();
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:14,代码来源:TestWIGChainedDelegates.cs

示例13: WaitForIdleOnWrongThread

        public void WaitForIdleOnWrongThread()
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool(10*1000, 25, 0);

            IWorkItemResult wir = smartThreadPool.QueueWorkItem(
                new WorkItemCallback(this.DoWaitForIdle),
                smartThreadPool);

            Exception e;
            wir.GetResult(out e);

            smartThreadPool.Shutdown();

            Assert.IsTrue(e is NotSupportedException);
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:15,代码来源:TestWaitForIdle.cs

示例14: DoWork

		public void DoWork(object [] states) 
		{ 
			SmartThreadPool smartThreadPool = new SmartThreadPool();

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

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

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

示例15: WaitForIdleEvent

        public void WaitForIdleEvent()
        {
            SmartThreadPool smartThreadPool = new SmartThreadPool();
            IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(1);
            ManualResetEvent wigIsIdle = new ManualResetEvent(false);

            workItemsGroup.OnIdle += wig => wigIsIdle.Set();

            workItemsGroup.QueueWorkItem(() => { });

            bool eventFired = wigIsIdle.WaitOne(100, true);

            smartThreadPool.Shutdown();

            Assert.IsTrue(eventFired);
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:16,代码来源:TestWIGWaitForIdle.cs


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