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


C# SmartThreadPool.Dispose方法代码示例

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


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

示例1: ManagerProc

        protected void ManagerProc()
        {
            STPStartInfo startInfo = new STPStartInfo();
            startInfo.MaxWorkerThreads = ExecutionThreads;
            SmartThreadPool st = new SmartThreadPool(startInfo);

            try
            {
                st.Start();
                while (!_stop)
                {
                    try
                    {
                        if (!st.IsIdle)
                        {
                            log.Warn("Thread pool not idle, waiting...");
                        }
                        else
                        {
                            log.Debug("Querying for ready processes");
                            IList<string> procs = Environment.GetKickableProcesses();

                            foreach (string procId in procs)
                            {
                                log.Debug("Queue <- {0}", procId);
                                st.QueueWorkItem(new WorkItemCallback(this.KickProcess), procId);
                            }
                            log.Debug("Enqueued {0} processes", procs.Count);
                        }
                        if (st.IsIdle)
                        {
                            _procNotifier.WaitOne(TimeSpan.FromSeconds(15.0), true);
                        }
                        else
                        {
                            //TODO: problem here - if some process takes a long time to
                            //kick, it will block process scheduling
                            //solution: we shouldn't wait for idle thread pool, but
                            //pump the queue all the time.
                            st.WaitForIdle(TimeSpan.FromHours(1.0));
                        }
                    }
                    catch (ThreadAbortException ex) {}
                    catch (ThreadInterruptedException ex) {}
                    catch (Exception ex)
                    {
                        log.Error("Manager thread error: {0}", ex);
                        DiagnosticEvent de = new DiagnosticEvent("NGEngine", ex);
                        de.Message = "NGEngine scheduler thread error";
                        MessageBus.Notify("NGengine", "Error", de, false);
                        if(!_stop) Thread.Sleep(30000);
                    }
                }
            }
            catch (ThreadAbortException ex) {}
            catch (ThreadInterruptedException ex) {}
            catch (Exception ex)
            {
                log.Error("Manager thread error: {0}", ex);
            }
            finally
            {
                log.Info("Shutting down thread pool");
                st.Shutdown(true, 10000);
                log.Info("Thread pool shut down");
                st.Dispose();
            }
        }
开发者ID:alasdairhurst,项目名称:nginn,代码行数:68,代码来源:NGEngine.cs

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

示例3: AlignPairsMultiThreaded


//.........这里部分代码省略.........
                                {
                                    AlignmentInfoElement aie = (AlignmentInfoElement)wirList[i].Result;
                                    if (aie!=null && (!alignedList.ContainsKey(aie.alignedLowSrcStr)||!alignedList[aie.alignedLowSrcStr].ContainsKey(aie.alignedLowTrgStr)))
                                    {
                                        res.Add(aie);
                                        if (!alignedList.ContainsKey(aie.alignedLowSrcStr)) alignedList.Add(aie.alignedLowSrcStr,new Dictionary<string, bool>());
                                        if (!alignedList[aie.alignedLowSrcStr].ContainsKey(aie.alignedLowTrgStr)) alignedList[aie.alignedLowSrcStr].Add(aie.alignedLowTrgStr,true);
                                    }
                                }
                            }
                        }
                        wirList.Clear();
                    }
                    try
                    {
                        IWorkItemResult<AlignmentInfoElement> wir = smartThreadPool.QueueWorkItem(
                            new Amib.Threading.Func<ProcessedTermEntry, ProcessedTermEntry, AlignmentInfoElement>(AlignSingleTermPair), srcPte, trgTerms[trgTerm]);
                        if (wir!=null) wirList.Add(wir);
                    }
                    catch
                    {
                        Log.Write("Thread exception catched - cannot create a new thread within term alignment!", LogLevelType.WARNING);
                    }
                    //smartThreadPool
                    /*while(smartThreadPool.PerformanceCountersReader.WorkItemsQueued>=100)
                    {
                        System.Threading.Thread.Sleep(5);
                    }*/

                    //AlignmentInfoElement aie = AlignSingleTermPair (configuration, trgTerms[trgTerm], interlinguaDictUsed, interlinguaTranslitUsed, srcFile, trgFile, excDict, srcStopWords, trgStopWords, lpeConf, srcPte);
                    //if (aie!=null)
                    //{
                        //res.Add(aie);
                    //}
                }
            }
            //Console.WriteLine();
            if (wirList.Count>0)
            {
                smartThreadPool.WaitForIdle();
                for(int i=0;i<wirList.Count;i++)
                {
                    if (wirList[i].IsCompleted && wirList[i].Exception==null)
                    {
                        AlignmentInfoElement aie = (AlignmentInfoElement)wirList[i].Result;
                        if (aie!=null && (!alignedList.ContainsKey(aie.alignedLowSrcStr)||!alignedList[aie.alignedLowSrcStr].ContainsKey(aie.alignedLowTrgStr)))
                        {
                            res.Add(aie);
                            if (!alignedList.ContainsKey(aie.alignedLowSrcStr)) alignedList.Add(aie.alignedLowSrcStr,new Dictionary<string, bool>());
                            if (!alignedList[aie.alignedLowSrcStr].ContainsKey(aie.alignedLowTrgStr)) alignedList[aie.alignedLowSrcStr].Add(aie.alignedLowTrgStr,true);
                        }
                    }
                    else if (!wirList[i].IsCompleted)
                    {
                        int times = 100;
                        while(!wirList[i].IsCompleted && times>0)
                        {
                            times--;
                            System.Threading.Thread.Sleep(100);
                        }
                        if (wirList[i].IsCompleted && wirList[i].Exception==null)
                        {
                            AlignmentInfoElement aie = (AlignmentInfoElement)wirList[i].Result;
                            if (aie!=null && (!alignedList.ContainsKey(aie.alignedLowSrcStr)||!alignedList[aie.alignedLowSrcStr].ContainsKey(aie.alignedLowTrgStr)))
                            {
                                res.Add(aie);
                                if (!alignedList.ContainsKey(aie.alignedLowSrcStr)) alignedList.Add(aie.alignedLowSrcStr,new Dictionary<string, bool>());
                                if (!alignedList[aie.alignedLowSrcStr].ContainsKey(aie.alignedLowTrgStr)) alignedList[aie.alignedLowSrcStr].Add(aie.alignedLowTrgStr,true);
                            }
                        }
                    }
                }
                wirList.Clear();
            }
            try{
                smartThreadPool.Shutdown(true,100);
                smartThreadPool.Dispose();
                smartThreadPool = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            catch
            {
                try
                {
                    smartThreadPool.Shutdown(true,100);
                    smartThreadPool.Dispose();
                    smartThreadPool = null;
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                catch
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
            }
            Log.Write ("Alignmet finished - "+ res.Count.ToString()+" term pairs aligned over the alignment threshold " +lpeConf.finalAlignmentThr.ToString()+".\n",LogLevelType.LIMITED_OUTPUT);
            return res;
        }
开发者ID:pmarcis,项目名称:mp-aligner,代码行数:101,代码来源:Alignment.cs


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