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


C# SmartThreadPool.Start方法代码示例

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


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

示例1: Test

        public void Test()
        {
            _requestReceived = new ManualResetEvent(false);

            /*setup + start listening*/
            var stub = new SipReceivedMessageProcessorStub(OnRequestReceived, (s,e) => { });

            var listeningPoint = new IPEndPoint(TestConstants.MyIpAddress, 33333);

            var f = new SipFactory();

            var stp = new SmartThreadPool();
            stp.Start();
            var provider = new SipContextSource(listeningPoint, stp);
            provider.AddListener(null);
            provider.Start();

            /*send a message to the listener*/
            var send = new SipRequestBuilder().Build();
            var requestBytes = SipFormatter.FormatMessage(send);

            var udpClient = new UdpClient();
            udpClient.Send(requestBytes, requestBytes.Length, listeningPoint);

            _requestReceived.WaitOne();

            var oc = ObjectComparer.Create();

            var received = stub.Requests.First();
            oc.Compare(received, send);
            Assert.True(oc.Differences.Count == 0, oc.DifferencesString);
        }
开发者ID:HNeukermans,项目名称:Hallo,代码行数:32,代码来源:UdpSipListenerTests.cs

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

示例3: BaseApproach

        public BaseApproach(int autoCompleteAfterNChars, StandardEvalOutput evalOutput, PrefixProfile queryPrefixProfile)
        {
            _autoCompleteAfterNChars = autoCompleteAfterNChars;
            _evalOutput = evalOutput;
            _queryPrefixProfile = queryPrefixProfile;

            _evalThreadPool = new SmartThreadPool(1000, 6);
            _evalThreadPool.Start(); // Setup and start the threadpool
        }
开发者ID:stewhir,项目名称:recent-robust-qac,代码行数:9,代码来源:BaseApproach.cs

示例4: IrrManager

        public IrrManager(Viewer viewer, int _id)
            : base(viewer, _id)
        {
            ChangeWorkDirectory(Util.ModelFolder);
            asset_max_threads = Reference.Viewer.Config.Source.Configs["Startup"].GetInt("asset_max_threads", 1);
            asset_fetch_retry = Reference.Viewer.Config.Source.Configs["Startup"].GetInt("asset_fetch_retry", 2);

            requestingThreadPool = new SmartThreadPool(120 * 1000, asset_max_threads);
            requestingThreadPool.Start();
        }
开发者ID:foxracle,项目名称:3di-viewer-rei,代码行数:10,代码来源:IrrManager.cs

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

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

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

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

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

示例10: GetUploadDataThreadPoolInstance

 public static SmartThreadPool GetUploadDataThreadPoolInstance()
 {
     if (uploadDataThreadPool == null)
     {
         lock (uploadDataThreadPoolLocker)
         {
             if (uploadDataThreadPool == null)
             {
                 if (uploadDataThreadPoolStartInfo == null)
                 {
                     throw new Exception("线程池需要启动参数");
                 }
                 uploadDataThreadPool = new SmartThreadPool(uploadDataThreadPoolStartInfo);
                 uploadDataThreadPool.Start();
             }
         }
     }
     return uploadDataThreadPool;
 }
开发者ID:xlgwr,项目名称:CollectPowerByModbus,代码行数:19,代码来源:PoolsManager.cs

示例11: GetCollectDataThreadPoolInstance

 public static SmartThreadPool GetCollectDataThreadPoolInstance()
 {
     if (collectDataThreadPool == null)
     {
         lock (collectDataThreadPoolLocker)
         {
             if (collectDataThreadPool == null)
             {
                 if (collectDataThreadPoolStartInfo == null)
                 {
                     throw new Exception("线程池需要启动参数");
                 }
                 collectDataThreadPool = new SmartThreadPool(collectDataThreadPoolStartInfo);
                 collectDataThreadPool.Start();
             }
         }
     }
     return collectDataThreadPool;
 }
开发者ID:xlgwr,项目名称:CollectPowerByModbus,代码行数:19,代码来源:PoolsManager.cs

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

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

示例14: DoWork

        public void DoWork(object [] states)
        {
            STPStartInfo stpStartInfo = new STPStartInfo();
            stpStartInfo.StartSuspended = true;

            SmartThreadPool smartThreadPool = new SmartThreadPool(stpStartInfo);

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

            // Start working on the work items in the queue
            smartThreadPool.Start();

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

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

示例15: CancelInQueueWorkItem

        public void CancelInQueueWorkItem()
        {
            Assert.Throws<WorkItemCancelException>(() =>
            {
                STPStartInfo stpStartInfo = new STPStartInfo();
                stpStartInfo.StartSuspended = true;

                bool hasRun = false;

                SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
                IWorkItemResult wir = stp.QueueWorkItem(
                    new WorkItemInfo() {Timeout = 500},
                    state =>
                    {
                        hasRun = true;
                        return null;
                    });

                Assert.IsFalse(wir.IsCanceled);

                Thread.Sleep(2000);

                Assert.IsTrue(wir.IsCanceled);

                stp.Start();
                stp.WaitForIdle();

                Assert.IsFalse(hasRun);

                try
                {
                    wir.GetResult();
                }
                finally
                {
                    stp.Shutdown();
                }
            });
        }
开发者ID:amibar,项目名称:SmartThreadPool,代码行数:39,代码来源:TestWorkItemTimeout.cs


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