Example #1
0
        public void Do(TaskGroupSetting s)
        {
            if (this.curTaskGroup == null)
            {
                return;
            }

            if (!this.curTaskGroup.PrepareDo(this.showListView, s))
            {
                GlobalVar.Instance.logger.Error("准备执行任务失败.");
                return;
            }

            GlobalVar.Instance.logger.Info("开始执行任务.");
            StartPerformance();

            isProducerThreadRunning = true;
            isWorkerThreadRunning   = true;
            isNoticeStop            = false;

            STPStartInfo stpStartInfo = new STPStartInfo();

            stpStartInfo.ThreadPoolName   = "扎古量产池";
            stpStartInfo.IdleTimeout      = 5000;
            stpStartInfo.MaxWorkerThreads = s.ThreadNum;
            stpStartInfo.MinWorkerThreads = 0;
            stpStartInfo.EnableLocalPerformanceCounters = true;
            smartThreadPool = new SmartThreadPool(stpStartInfo);
            performance.Init(smartThreadPool);

            tasksProducerThread = new Thread(new ThreadStart(this.TasksProducerThreadMain));
            tasksProducerThread.IsBackground = true;
            tasksProducerThread.Start();
        }
Example #2
0
    // Use this for initialization
    void Start()
    {
        running = true;

        STPStartInfo stpStartInfo = new STPStartInfo();

        stpStartInfo.IdleTimeout      = 50 * 1000;
        stpStartInfo.MaxWorkerThreads = 10;
        stpStartInfo.MinWorkerThreads = 2;
        if (_useWindowsPerformanceCounters)
        {
            stpStartInfo.PerformanceCounterInstanceName = "Test SmartThreadPool";
        }
        else
        {
            stpStartInfo.EnableLocalPerformanceCounters = true;
        }
        _smartThreadPool = new SmartThreadPool(stpStartInfo);
        _workItemsGroup  = _smartThreadPool;

        workItemsProducerThread = new Thread(new ThreadStart(this.WorkItemsProducer));
        workItemsProducerThread.IsBackground = true;
        workItemsProducerThread.Start();
        InitializeLocalPerformanceCounters();
    }
Example #3
0
        public void QueueWorkItem_WhenMaxIsSet_ThrowsExceptionWhenHit()
        {
            Assert.ThrowsException <QueueRejectedException>(() =>
            {
                var info = new STPStartInfo
                {
                    MaxQueueLength   = 1,
                    MinWorkerThreads = 1,
                    MaxWorkerThreads = 1,
                };
                var pool = new STP(info);
                pool.Start();

                try
                {
                    pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.
                    pool.QueueWorkItem(SleepForOneSecond); // No waiters available, pool at max threads. Queued.
                }
                catch (QueueRejectedException e)
                {
                    throw new Exception("Caught QueueRejectedException too early: ", e);
                }

                // No waiters available, queue is at max (1). Throws.
                pool.QueueWorkItem(SleepForOneSecond);
            });
        }
Example #4
0
        private void btnStart_Click(object sender, System.EventArgs e)
        {
            UpdateControls(true);
            workItemsCompleted = 0;
            workItemsGenerated = 0;

            STPStartInfo stpStartInfo = new STPStartInfo();

            stpStartInfo.IdleTimeout      = Convert.ToInt32(spinIdleTimeout.Value) * 1000;
            stpStartInfo.MaxWorkerThreads = Convert.ToInt32(spinMaxThreads.Value);
            stpStartInfo.MinWorkerThreads = Convert.ToInt32(spinMinThreads.Value);
            if (_useWindowsPerformanceCounters)
            {
                stpStartInfo.PerformanceCounterInstanceName = "Test SmartThreadPool";
            }
            else
            {
                stpStartInfo.EnableLocalPerformanceCounters = true;
            }

            _smartThreadPool = new SmartThreadPool(stpStartInfo);

            //_workItemsGroup = _smartThreadPool.CreateWorkItemsGroup(1);
            _workItemsGroup = _smartThreadPool;

            workItemsProducerThread = new Thread(new ThreadStart(this.WorkItemsProducer));
            workItemsProducerThread.IsBackground = true;
            workItemsProducerThread.Start();
        }
Example #5
0
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            if (_running)
            {
                _wakeupEvent.Set();
                _stp.Cancel();
                _stp.Shutdown(false, 5000);
                _stp             = null;
                btnStart.Content = "Start";
                //txtIdleTimeout.Enabled = true;
                _running = false;
            }
            else
            {
                usageHistoryControl1.Reset();
                usageControl1.Value1 = 0;
                usageControl1.Value2 = 0;
                _wakeupEvent.Set();
                _running         = true;
                btnStart.Content = "Stop";
                //txtIdleTimeout.Enabled = false;
                STPStartInfo stpStartInfo = new STPStartInfo()
                {
                    MinWorkerThreads = Convert.ToInt32(txtMinThreads.Text),
                    MaxWorkerThreads = Convert.ToInt32(txtMaxThreads.Text),
                    IdleTimeout      = Convert.ToInt32(txtIdleTimeout.Text) * 1000,
                    EnableLocalPerformanceCounters = true,
                };

                _stp = new SmartThreadPool(stpStartInfo);
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            STPStartInfo startInfo = new STPStartInfo();

            startInfo.ThreadPoolName   = "KZL Thread";
            startInfo.IdleTimeout      = 2000;
            startInfo.MaxWorkerThreads = 15;
            startInfo.MinWorkerThreads = 2;

            SmartThreadPool stp = new SmartThreadPool(startInfo);

            int[] numbers = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            Console.WriteLine("In Main thread...");

            IWorkItemResult iwir = stp.QueueWorkItem(new WorkItemCallback(Callback),
                                                     new object[] { numbers }
                                                     );

            // do some other work
            waitHandle.WaitOne();
            //System.Threading.Thread.Sleep(6000); // suspend main thread

            Console.WriteLine("Secondary thread finished.");
            double result = (double)iwir.Result;

            stp.Shutdown();

            Console.WriteLine("Result is {0}", result.ToString());
            Console.ReadLine();
        }
Example #7
0
        public async Task Execute(IJobExecutionContext context)
        {
            if (!IsRunning)
            {
                IsRunning = true;
                baseUrl   = context.JobDetail.JobDataMap.Get("baseUrl").ToString();
                proxyUrl  = context.JobDetail.JobDataMap.Get("proxyUrl").ToString();
                feedNode  = context.JobDetail.JobDataMap.Get("node") as FeedNode;

                Logger.GetLogger(baseUrl).Info("start feed job execute");

                var task = Task.Factory.StartNew(() =>
                {
                    var feeds   = GetFeedJobs(baseUrl, proxyUrl, feedNode);
                    var compile = new UrlCompile();

                    var stpStartInfo = new STPStartInfo
                    {
                        IdleTimeout      = 3000,
                        MaxWorkerThreads = 8,
                        MinWorkerThreads = 0
                    };

                    var pool  = new SmartThreadPool(stpStartInfo);
                    var waits = new List <IWorkItemResult>();

                    foreach (var feed in feeds)
                    {
                        var addrs = compile.GetResult(feed.Address);

                        Logger.GetLogger(baseUrl).Info("compile address " + feed.Address + " result " + string.Join(",", addrs));

                        foreach (var addr in addrs)
                        {
                            feed.Address = addr.ToString();

                            var item = pool.QueueWorkItem((u) =>
                            {
                                DoTask(u, true);
                            }, feed);

                            waits.Add(item);
                        }
                    }

                    SmartThreadPool.WaitAll(waits.ToArray());

                    pool.Shutdown(true, 1000);
                    pool.Dispose();
                    pool = null;
                    waits.Clear();
                });

                await task;

                IsRunning = false;

                Logger.GetLogger(baseUrl).Info("end feed job execute");
            }
        }
Example #8
0
        //private int CacheRegionsDistance = 256;

        #region INonSharedRegionModule Members
        public virtual void Initialize(IConfigSource config)
        {
            IConfig startupConfig = config.Configs["Startup"];

            if (startupConfig.GetString("WorldMapModule", "WorldMap") == "WorldMap")
            {
                m_Enabled = true;
            }

            STPStartInfo reqPoolStartInfo = new STPStartInfo();

            reqPoolStartInfo.MaxWorkerThreads = 2;
            reqPoolStartInfo.IdleTimeout      = 5 * 60 * 1000;
            reqPoolStartInfo.ThreadPriority   = ThreadPriority.Lowest;

            STPStartInfo infoReqPoolStartInfo = new STPStartInfo();

            reqPoolStartInfo.MaxWorkerThreads = 4;
            reqPoolStartInfo.IdleTimeout      = 5 * 60 * 1000;
            reqPoolStartInfo.ThreadPriority   = ThreadPriority.Lowest;

            _blockRequestPool      = new SmartThreadPool(reqPoolStartInfo);
            _blockRequestPool.Name = "Map Block Requests";
            _infoRequestPool       = new SmartThreadPool(infoReqPoolStartInfo);
            _infoRequestPool.Name  = "Map Info Requests";
        }
        /// <summary>
        /// Example of how to use the post execute callback
        /// </summary>
        private bool DoTestDefaultPostExecute(CallToPostExecute callToPostExecute, bool answer)
        {
            STPStartInfo stpStartInfo = new STPStartInfo();

            stpStartInfo.CallToPostExecute           = callToPostExecute;
            stpStartInfo.PostExecuteWorkItemCallback = new PostExecuteWorkItemCallback(this.DoSomePostExecuteWork);

            SmartThreadPool smartThreadPool = new SmartThreadPool(stpStartInfo);

            bool success = false;

            PostExecuteResult postExecuteResult = new PostExecuteResult();

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

            if (!wir.IsCompleted)
            {
                int result = (int)wir.GetResult();
                success = (1 == result);
                success = success && (postExecuteResult.wh.WaitOne(1000, true) == answer);
            }

            smartThreadPool.Shutdown();

            return(success);
        }
Example #10
0
        public void DontDisposeCallerState()
        {
            STPStartInfo stpStartInfo = new STPStartInfo();

            stpStartInfo.DisposeOfStateObjects = false;

            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();
            bool success = (1 == nonDisposableCallerState.Value);

            wir2.GetResult();

            success = success && (1 == disposableCallerState.Value);

            smartThreadPool.Shutdown();

            Assert.IsTrue(success);
        }
        public void Start(int MaxThreadCount, int minThreadCount = _DefaultMinThreadCount)
        {
            lock (m_SyncRoot)
            {
                if (m_Disposed)
                {
                    throw new ObjectDisposedException(GetType().FullName);
                }

                if (m_Started)
                {
                    throw new InvalidOperationException("SmartThreadPool already started.");
                }

                STPStartInfo startInfo = new STPStartInfo();
                startInfo.MinWorkerThreads = minThreadCount;
                startInfo.MaxWorkerThreads = MaxThreadCount;
                startInfo.IdleTimeout      = 20000; // After 20 seconds, a thread counts as an idle one
                startInfo.EnableLocalPerformanceCounters = true;
                startInfo.ThreadPoolName = "Smart Threadpool";
                m_SmartThreadPool        = new SmartThreadPool(startInfo);
                m_SmartThreadPool.Start();
                statisticsTimer = new Timer(new TimerCallback(StatisticsTimer), null, 5000, 120000);
                m_Started       = true;
            }
        }
Example #12
0
        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");
        }
Example #13
0
 private void SetRunningState(bool newRunningState)
 {
     btnStartStop.Text = newRunningState ? "Stop" : "Start";
     if (newRunningState)
     {
         STPStartInfo stpStartInfo = new STPStartInfo()
         {
             IdleTimeout      = Convert.ToInt32(spnIdleTimeout.Value) * 1000,
             MaxWorkerThreads = Convert.ToInt32(spnMaxThreads.Value),
             MinWorkerThreads = Convert.ToInt32(spnMinThreads.Value),
             EnableLocalPerformanceCounters = true,
         };
         _stp = new SmartThreadPool(stpStartInfo);
     }
     else
     {
         if (null != _stp)
         {
             _stp.Shutdown();
         }
         _stp = null;
         usageHistoryControl1.Reset();
         usageControl1.Value1 = 0;
         usageControl1.Value2 = 0;
     }
     spnIdleTimeout.Enabled = !newRunningState;
     uiTimer.Enabled        = newRunningState;
     wiTimer.Enabled        = newRunningState;
     running = newRunningState;
 }
Example #14
0
        public void QueueWorkItem_WhenQueueMaxLengthZero_RejectsInsteadOfQueueing()
        {
            new Thread(() => Assert.ThrowsException <QueueRejectedException>(() =>
            {
                var info = new STPStartInfo
                {
                    MaxQueueLength   = 0,
                    MinWorkerThreads = 2,
                    MaxWorkerThreads = 2,
                };
                var pool = new STP(info);
                pool.Start();

                try
                {
                    pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.
                    pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.
                }
                catch (QueueRejectedException e)
                {
                    throw new Exception("Caught QueueRejectedException too early: ", e);
                }

                pool.QueueWorkItem(SleepForOneSecond);
            })).Start();
        }
Example #15
0
        private bool InitializePerformanceCounters()
        {
            if (!PerformanceCounterCategory.Exists("测试线程池"))
            {
                STPStartInfo stpStartInfo = new STPStartInfo();
                stpStartInfo.PerformanceCounterInstanceName = "测试线程池工具";

                SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
                stp.Shutdown();

                if (!PerformanceCounterCategory.Exists("测试线程池"))
                {
                    //MessageBox.Show("创建性能监视器失败.\r\n如果你使用Windows Vista 或者Windows 7,请使用管理员权限执行本程序.\r\n\r\n将使用内置性能监视器.", "测试线程池工具", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                Process process = new Process();
                process.StartInfo.FileName = Application.ExecutablePath;

                try
                {
                    process.Start();
                }
                catch (Exception e)
                {
                    e.GetHashCode();
                    MessageBox.Show("未知错误.", "测试线程池工具");
                }

                return(false);
            }

            return(true);
        }
Example #16
0
        private void materialRaisedButton11_Click(object sender, EventArgs e)
        {
            startTime = System.DateTime.Now;
            running   = true;
            UpdateControls(true);

            workItemsCompleted = 0;
            workItemsGenerated = 0;

            STPStartInfo stpStartInfo = new STPStartInfo();

            stpStartInfo.IdleTimeout      = Convert.ToInt32(materialSingleLineTextField4.Text) * 1000;
            stpStartInfo.MaxWorkerThreads = Convert.ToInt32(materialSingleLineTextField5.Text);
            stpStartInfo.MinWorkerThreads = 0;
            if (_useWindowsPerformanceCounters)
            {
                stpStartInfo.PerformanceCounterInstanceName = "测试线程池工具";
            }
            else
            {
                stpStartInfo.EnableLocalPerformanceCounters = true;
            }
            _smartThreadPool = new SmartThreadPool(stpStartInfo);
            _workItemsGroup  = _smartThreadPool;

            workItemsProducerThread = new Thread(new ThreadStart(this.WorkItemsProducer));
            workItemsProducerThread.IsBackground = true;
            workItemsProducerThread.Start();
        }
Example #17
0
        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();
        }
        public void Initialise(IConfigSource config)
        {
            m_proxyurl     = config.Configs["Startup"].GetString("HttpProxy");
            m_proxyexcepts = config.Configs["Startup"].GetString("HttpProxyExceptions");

            HttpRequestClass.HttpBodyMaxLenMAX = config.Configs["Network"].GetInt("HttpBodyMaxLenMAX", 16384);


            m_outboundUrlFilter = new OutboundUrlFilter("Script HTTP request module", config);
            int maxThreads = 15;

            IConfig httpConfig = config.Configs["HttpRequestModule"];

            if (httpConfig != null)
            {
                maxThreads = httpConfig.GetInt("MaxPoolThreads", maxThreads);
            }

            m_pendingRequests = new Dictionary <UUID, HttpRequestClass>();

            // First instance sets this up for all sims
            if (ThreadPool == null)
            {
                STPStartInfo startInfo = new STPStartInfo();
                startInfo.IdleTimeout      = 20000;
                startInfo.MaxWorkerThreads = maxThreads;
                startInfo.MinWorkerThreads = 1;
                startInfo.ThreadPriority   = ThreadPriority.BelowNormal;
                startInfo.StartSuspended   = true;
                startInfo.ThreadPoolName   = "ScriptsHttpReq";

                ThreadPool = new SmartThreadPool(startInfo);
                ThreadPool.Start();
            }
        }
Example #19
0
        public void DoWork(object[] states)
        {
            STPStartInfo stp = new STPStartInfo();

            stp.DisposeOfStateObjects = true;
            stp.CallToPostExecute     = CallToPostExecute.Always;
            stp.ThreadPriority        = ThreadPriority.Highest;
            stp.UseCallerCallContext  = true;
            stp.MaxWorkerThreads      = 20;
            SmartThreadPool smartThreadPool = new SmartThreadPool();

            smartThreadPool.MaxThreads = states.Length;
            smartThreadPool.MinThreads = 1;
            foreach (object state in states)
            {
                IWorkItemResult i = smartThreadPool.QueueWorkItem(new
                                                                  WorkItemCallback(this.DoSomeWork), state);
                Data.Add(i.Result.ToString());
            }

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

            smartThreadPool.Shutdown();
        }
        public void Init()
        {
            STPStartInfo stpStartInfo = new STPStartInfo();

            stpStartInfo.FillStateWithArgs = true;
            _stp = new SmartThreadPool(stpStartInfo);
        }
Example #21
0
        // This method is a work around for the Peformance Counter issue.
        // When the first SmartThreadPool is created with a Peformance
        // Counter name on a machine, it creates the SmartThreadPool
        // Peformance Counter category. In this demo I am using the Performance
        // Counters to update the GUI.
        // The issue is that if this demo runs for the first time on the
        // machine, it creates the Peformance Counter category and then
        // uses it.
        // I don't know why, but every time the demo runs for the first
        // time on a machine, it fails to connect to the Peformance Counters,
        // because it can't find the Peformance Counter category.
        // The work around is to check if the category exists, and if not
        // create a SmartThreadPool instance that will create the category.
        // After that I spawn another process that runs the demo.
        // I tried the another work around and thats to check for the category
        // existance, run a second process that will create the category,
        // and then continue with the first process, but it doesn't work.
        // Thank you for reading the whole comment. If you have another way
        // to solve this issue please contact me: [email protected].
        private static bool InitializePerformanceCounters()
        {
            if (!PerformanceCounterCategory.Exists("SmartThreadPool"))
            {
                STPStartInfo stpStartInfo = new STPStartInfo();
                stpStartInfo.PerformanceCounterInstanceName = "Test SmartThreadPool";

                SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
                stp.Shutdown();

                if (!PerformanceCounterCategory.Exists("SmartThreadPool"))
                {
                    MessageBox.Show("Failed to create Performance Counters category.\r\nIf you run on Vista, Windows 7, or later, you need to run for the first time as Administrator to create the performance counters category.\r\n\r\nUsing internal performance counters instead.", "Test Smart Thread Pool", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                Process process = new Process();
                process.StartInfo.FileName = Application.ExecutablePath;

                try
                {
                    process.Start();
                }
                catch (Exception e)
                {
                    e.GetHashCode();
                    MessageBox.Show("If this is the first time you get this message,\r\nplease try to run the demo again.", "Test Smart Thread Pool");
                }

                return(false);
            }

            return(true);
        }
Example #22
0
        public void Start()
        {
            STPStartInfo START_INFO = new STPStartInfo
            {
                WorkItemPriority = Amib.Threading.WorkItemPriority.Normal,
                MinWorkerThreads = 0,
                MaxWorkerThreads = Config.Settings.Instance.CFWorkerThreads,
                IdleTimeout      = THREADPOOL_IDLE_TIMEOUT,
            };

            _threadPool      = new SmartThreadPool(START_INFO);
            _threadPool.Name = "Cloudfiles";

            Func <CloudFilesAssetWorker> ctorFunc = () => { return(new CloudFilesAssetWorker(_readTimeout, _writeTimeout)); };

            _asyncAssetWorkers = new ObjectPool <CloudFilesAssetWorker>(Config.Settings.Instance.CFWorkerThreads * 2, ctorFunc);

            _assetCache = new Cache.Cache(MAX_IDLE_CACHE_ENTRY_AGE);

            if (!Config.Settings.Instance.DisableWritebackCache)
            {
                _diskWriteBack = new Cache.DiskWriteBackCache();
                _diskWriteBack.Start();
            }

            //start maintaining the cache
            _maintTimer = new Timer(this.Maintain, null, MAINTENANCE_INTERVAL, MAINTENANCE_INTERVAL);
        }
Example #23
0
        /// <summary>
        /// 后台消息业务处理对象启动
        /// </summary>
        /// <returns></returns>
        public bool InitServer()
        {
            try
            {
                //获取线程空闲超时时间(单位:秒)、最大线程数
                _idleTimeout      = 10;
                _maxWorkerThreads = 10;
            }
            catch (Exception ex)
            {
                //写日志(预留),不退出
            }
            //////////////////////////////////////////////////////////////////////////////////////////////////
            try
            {
                STPStartInfo stpStartInfo = new STPStartInfo();
                stpStartInfo.IdleTimeout      = _idleTimeout * 2000;
                stpStartInfo.MaxWorkerThreads = _maxWorkerThreads;
                stpStartInfo.MinWorkerThreads = _minWorkerThreads;
                stpStartInfo.PerformanceCounterInstanceName = "Pool";
                _smartThreadPool = new SmartThreadPool(stpStartInfo);
                _workItemsGroup  = _smartThreadPool;
                //线程池启动成功,写日志(预留)
                return(true);
            }
            catch (Exception ex)
            {
                //Helper.Log.SaveException("Exception", ex);
                //写日志(预留)

                return(false);
            }
        }
Example #24
0
        private SmartThreadPool GetStaThreadPool()
        {
            var stpStartInfo = new STPStartInfo {
                ApartmentState = ApartmentState.STA
            };

            return(new SmartThreadPool(stpStartInfo));
        }
Example #25
0
 public STPStartInfo(STPStartInfo stpStartInfo) : base(stpStartInfo)
 {
     this._idleTimeout      = stpStartInfo._idleTimeout;
     this._minWorkerThreads = stpStartInfo._minWorkerThreads;
     this._maxWorkerThreads = stpStartInfo._maxWorkerThreads;
     this._threadPriority   = stpStartInfo._threadPriority;
     this._pcInstanceName   = stpStartInfo._pcInstanceName;
 }
Example #26
0
        private SmartThreadPool SetupSmartThreadPool(int threads)
        {
            STPStartInfo startInfo = new STPStartInfo();

            startInfo.StartSuspended   = true;
            startInfo.MaxWorkerThreads = threads;
            startInfo.ThreadPriority   = System.Threading.ThreadPriority.Normal;
            return(new SmartThreadPool(startInfo));
        }
        public void Init()
        {
            STPStartInfo stpStartInfo = new STPStartInfo
            {
                FillStateWithArgs = true//FIXME:FillStateWithParams
            };

            _stp = new STP(stpStartInfo);
        }
Example #28
0
 public void StpStartInfo_WithNegativeMaxQueueLength_FailsValidation()
 {
     Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
     {
         var info = new STPStartInfo
         {
             MaxQueueLength = -1,
         };
         new STP(info);
     });
 }
Example #29
0
        public void StpStartInfo_WithZeroMaxQueueLength_IsAllowed()
        {
            var info = new STPStartInfo
            {
                MaxQueueLength = 0,
            };
            var pool = new STP(info);

            pool.Start();
            Assert.IsTrue(0 == pool.STPStartInfo.MaxQueueLength);
        }
Example #30
0
        public static void init()
        {
            STPStartInfo stpStartInfo = new STPStartInfo();

            stpStartInfo.MaxWorkerThreads  = Convert.ToInt32(ConfigService.get("thread.maxCnt"));
            stpStartInfo.MinWorkerThreads  = 0;
            stpStartInfo.ThreadPriority    = ThreadPriority.BelowNormal;
            stpStartInfo.CallToPostExecute = CallToPostExecute.Never;

            threadPool = new SmartThreadPool(stpStartInfo);
        }