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


C# SmartThreadPool.QueueWorkItem方法代码示例

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


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

示例1: 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

示例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: WorkItemWaitCanceling

        public void WorkItemWaitCanceling()
        {
            Assert.Throws<WorkItemTimeoutException>(() =>
            {
                SmartThreadPool smartThreadPool = new SmartThreadPool();

                ManualResetEvent cancelWaitHandle = new ManualResetEvent(false);

                // Queue a work item that will occupy the thread in the pool
                IWorkItemResult wir1 =
                    smartThreadPool.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null);

                // Queue another work item that will wait for the first to complete
                IWorkItemResult wir2 =
                    smartThreadPool.QueueWorkItem(new WorkItemCallback(this.SignalCancel), cancelWaitHandle);

                try
                {
                    wir1.GetResult(System.Threading.Timeout.Infinite, true, cancelWaitHandle);
                }
                finally
                {
                    smartThreadPool.Shutdown();
                }
            });
        }
开发者ID:amibar,项目名称:SmartThreadPool,代码行数:26,代码来源:TestGetResult.cs

示例4: Migrate15Minute

 public void Migrate15Minute(SmartThreadPool tp)
 {
     tp.QueueWorkItem(() =>
     {
         GameSessionUserStats15MinuteMigrate();
     });
     tp.QueueWorkItem(() =>
     {
         GameUserActivity15MinuteMigrate();
     });
 }
开发者ID:parallaxisjones,项目名称:angularmetricsproj,代码行数:11,代码来源:DataBuilder.cs

示例5: Migrate1Hour

 public void Migrate1Hour(SmartThreadPool tp)
 {
     tp.QueueWorkItem(() =>
     {
         GameSessionUserStats60Migrate();
     });
     tp.QueueWorkItem(() =>
     {
         GameUserActivity60Migrate();
     });
 }
开发者ID:parallaxisjones,项目名称:angularmetricsproj,代码行数:11,代码来源:DataBuilder.cs

示例6: ExceptionThrowing

        public void ExceptionThrowing()
        {
            SmartThreadPool _smartThreadPool = new SmartThreadPool();

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

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

            try
            {
                wir.GetResult();
            }
            catch(WorkItemResultException wire)
            {
                Assert.IsTrue(wire.InnerException is DivideByZeroException);
                return;
            }
            catch(Exception e)
            {
                e.GetHashCode();
                Assert.Fail();
            }
            Assert.Fail();
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:27,代码来源:TestExceptions.cs

示例7: ExceptionReturning

        public void ExceptionReturning()
        {
            bool success = true;

            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 = null;
            try
            {
                wir.GetResult(out e);
            }
            catch (Exception ex)
            {
                ex.GetHashCode();
                success = false;
            }

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

示例8: TimeoutInProgressWorkItemWithSample

        public void TimeoutInProgressWorkItemWithSample()
        {
            bool timedout = false;
            ManualResetEvent waitToStart = new ManualResetEvent(false);
            ManualResetEvent waitToComplete = new ManualResetEvent(false);

            SmartThreadPool stp = new SmartThreadPool();
            IWorkItemResult wir = stp.QueueWorkItem(
                new WorkItemInfo() { Timeout = 500 },
                state =>
                {
                    waitToStart.Set();
                    Thread.Sleep(1000);
                    timedout = SmartThreadPool.IsWorkItemCanceled;
                    waitToComplete.Set();
                    return null;
                });

            waitToStart.WaitOne();

            waitToComplete.WaitOne();

            Assert.IsTrue(timedout);

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

示例9: getImagesAsync

        public static void getImagesAsync(List<FilmData> tempFilmList)
        {
            if (isNetworkAvailable())
            {

                SmartThreadPool smartThreadPool = new SmartThreadPool(
                                                                        15 * 1000,   // Idle timeout in milliseconds
                                                                        25,         // Threads upper limit
                                                                        1);         // Threads lower limit
                var bw = new System.ComponentModel.BackgroundWorker();
                bw.DoWork += (s, args) =>
                {
                    foreach (FilmData item in tempFilmList)
                    {
                        if (IsolatedStorageHelper.isFileAlreadySaved(item.imageUrl))
                            ImageHelper.addDownloadedItemsToFilmCollection(item.imageUrl);
                        else
                            smartThreadPool.QueueWorkItem(() => getImageFromUrl(item.imageUrl));
                    }

                    smartThreadPool.WaitForIdle(); // Wait for the completion of all work items
                };
                bw.RunWorkerAsync();
            }
        }
开发者ID:asdForever,项目名称:TouchInstinctTestApp,代码行数:25,代码来源:Networking.cs

示例10: WaitAllT

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

            bool success = true;

            IWorkItemResult<int>[] wirs = new IWorkItemResult<int>[5];

            for (int i = 0; i < wirs.Length; ++i)
            {
                wirs[i] = smartThreadPool.QueueWorkItem(new Func<int, int, int>(System.Math.Min), i, i + 1);
            }

            SmartThreadPool.WaitAll(wirs);

            for (int i = 0; i < wirs.Length; ++i)
            {
                if (!wirs[i].IsCompleted)
                {
                    success = false;
                    break;
                }

                int result = wirs[i].GetResult();
                if (i != result)
                {
                    success = false;
                    break;
                }
            }

            smartThreadPool.Shutdown();

            Assert.IsTrue(success);
        }
开发者ID:amibar,项目名称:SmartThreadPool,代码行数:35,代码来源:TestMultipleWorkItems.cs

示例11: WaitAny

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

			bool success = false;

			IWorkItemResult [] wirs = new IWorkItemResult[5];

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

			int index = SmartThreadPool.WaitAny(wirs);

			if (wirs[index].IsCompleted)
			{
				int result = (int)wirs[index].GetResult();
				if (1 == result)
				{
					success = true;
				}
			}

			smartThreadPool.Shutdown();

			Assert.IsTrue(success);
		} 
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:29,代码来源:TestMultipleWorkItems.cs

示例12: 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

示例13: 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

示例14: Main

        public static void Main()
        {
            SmartThreadPool stp = new SmartThreadPool();
            stp.OnThreadInitialization += OnInitialization;
            stp.OnThreadTermination += OnTermination;

            stp.QueueWorkItem(DoSomeWork);
        }
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:8,代码来源:ThreadEventsExample.cs

示例15: GoodCallback

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

            stp.QueueWorkItem(new WorkItemCallback(DoWork));

            stp.WaitForIdle();

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


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