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


C# SmartThreadPool.WaitForIdle方法代码示例

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


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

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

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

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

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

示例6: GoodCallback

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

            stp.QueueWorkItem(new WorkItemCallback(DoWork));

            stp.WaitForIdle();

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

示例7: Start

        /// <summary>
        /// Starts the tasks execution.
        /// </summary>
        /// <returns>If has reach the timeout false, otherwise true.</returns>
        public override bool Start()
        {
            base.Start();
            m_threadPool = new SmartThreadPool();

            try
            {
                m_threadPool.MinThreads = MinThreads;
                m_threadPool.MaxThreads = MaxThreads;
                var workItemResults = new IWorkItemResult[Tasks.Count];

                for (int i = 0; i < Tasks.Count; i++)
                {
                    var t = Tasks[i];
                    workItemResults[i] = m_threadPool.QueueWorkItem(new WorkItemCallback(Run), t);
                }

                m_threadPool.Start();

                // Timeout was reach?
                if (!m_threadPool.WaitForIdle(Timeout.TotalMilliseconds > int.MaxValue ? int.MaxValue : Convert.ToInt32(Timeout.TotalMilliseconds)))
                {
                    if (m_threadPool.IsShuttingdown)
                    {
                        return true;
                    }
                    else
                    {
                        m_threadPool.Cancel(true);
                        return false;
                    }
                }

                foreach (var wi in workItemResults)
                {
                    Exception ex;
                    wi.GetResult(out ex);

                    if (ex != null)
                    {
                        throw ex;
                    }
                }

                return true;
            }
            finally
            {
                m_threadPool.Shutdown(true, 1000);
                m_threadPool.Dispose();
                IsRunning = false;
            }
        }
开发者ID:denisbarboni,项目名称:Projeto-AG,代码行数:57,代码来源:SmartThreadPoolTaskExecutor.cs

示例8: WaitForIdle

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

            ManualResetEvent isRunning = new ManualResetEvent(false);

            for(int i = 0; i < 4; ++i)
            {
                smartThreadPool.QueueWorkItem(delegate { isRunning.WaitOne(); });
            }

            bool success = !smartThreadPool.WaitForIdle(1000);

            isRunning.Set();

            success = success && smartThreadPool.WaitForIdle(1000);

            smartThreadPool.Shutdown();

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

示例9: Parse

        public Character Parse(Character character, bool force)
        {
            stopwatch.Reset();
            Stopwatch watch = new Stopwatch();
            watch.Start();

            _current = character;

            // Only parse the character once a day unless forced
            if (character.LastParseDate.HasValue &&
                character.LastParseDate.Value.AddDays(7) > DateTime.Now && !force)
            {
                return character;
            }

            ParseCharacterInformation(character);

            //character.Achievements.Clear();

            string mainAchievementPageUrl = string.Format("http://{2}.battle.net/wow/en/character/{0}/{1}/achievement", character.Server, character.Name, character.Region);
            HtmlDocument doc = DownloadPage(mainAchievementPageUrl);
            List<AchievedAchievement> achievements = new List<AchievedAchievement>();

            ProcessPageForAchievements(doc.DocumentNode, character);
            pagesToParse = new List<HtmlDocument>();
            IList<string> extraPages = FindSubAchievementPages(doc.DocumentNode);

            SmartThreadPool pool = new SmartThreadPool();
            foreach (string pageUrl in extraPages)
            {
                pool.QueueWorkItem(new WorkItemCallback(ProcessPageOnNewThread), pageUrl);
            }

            pool.Start();
            pool.WaitForIdle();

            try
            {
                foreach (HtmlDocument page in pagesToParse)
                {
                    ProcessPageForAchievements(page.DocumentNode, character);
                }
            }
            catch (IndexOutOfRangeException)
            {
            }
            character.LastParseDate = DateTime.Now;
            character.CurrentPoints = character.TotalAchievementPoints;
            watch.Stop();

            return character;
        }
开发者ID:blat001,项目名称:Achievement-Sherpa,代码行数:52,代码来源:CharacterParser.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: 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

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

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

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

示例15: ChainedDelegatesPostExecute

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

            PostExecuteWorkItemCallback postExecuteWorkItemCallback = DoPostExecute;
            postExecuteWorkItemCallback += DoPostExecute;

            stp.QueueWorkItem(
                new WorkItemCallback(DoWork),
                null,
                postExecuteWorkItemCallback);

            stp.WaitForIdle();

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


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