Esempio n. 1
0
 public ThreadPool(ThreadPoolStartInfo startInfo)
 {
     _startInfo = startInfo;
     if (!_startInfo.DelayedInit)
     {
         Init();
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes the ThreadPool. Note: if the threadpool is configured for delayed
 /// initialization then threads aren't created until the the first work is added
 /// to the threadpool queue.
 /// </summary>
 private void Init()
 {
     ServiceRegistration.Get <ILogger>().Info("ThreadPool.Init()");
     _cancelWaitHandle.Reset();
     ThreadPoolStartInfo.Validate(_startInfo);
     _inUseThreads   = 0;
     _itemsProcessed = 0;
     if (!_startInfo.DelayedInit)
     {
         StartThreads(GetOptimalThreadCount());
     }
 }
 /// <summary>
 /// Validates the given ThreadPoolStartInfo.
 /// </summary>
 /// <param name="tpsi">ThreadPoolStartInfo to validate.</param>
 /// <exception cref="ArgumentOutOfRangeException">If MinimumThreads, MaximumThreads or ThreadIdleTimeout
 /// are invalid.</exception>
 public static void Validate(ThreadPoolStartInfo tpsi)
 {
     if (tpsi.MinimumThreads < 1)
     {
         throw new ArgumentOutOfRangeException("MinimumThreads", tpsi.MinimumThreads, "cannot be less than one");
     }
     if (tpsi.MaximumThreads < 1)
     {
         throw new ArgumentOutOfRangeException("MaximumThreads", tpsi.MaximumThreads, "cannot be less than one");
     }
     if (tpsi.MinimumThreads > tpsi.MaximumThreads)
     {
         throw new ArgumentOutOfRangeException("MinimumThreads", tpsi.MinimumThreads, "must be less or equal to MaximumThreads");
     }
     if (tpsi.ThreadIdleTimeout < 0)
     {
         throw new ArgumentOutOfRangeException("ThreadIdleTimeout", tpsi.ThreadIdleTimeout, "cannot be less than zero");
     }
 }
Esempio n. 4
0
 public ThreadPool(ThreadPoolStartInfo startInfo)
 {
   _startInfo = startInfo;
   if (!_startInfo.DelayedInit)
     Init();
 }
 /// <summary>
 /// Validates the given ThreadPoolStartInfo.
 /// </summary>
 /// <param name="tpsi">ThreadPoolStartInfo to validate.</param>
 /// <exception cref="ArgumentOutOfRangeException">If MinimumThreads, MaximumThreads or ThreadIdleTimeout
 /// are invalid.</exception>
 public static void Validate(ThreadPoolStartInfo tpsi)
 {
   if (tpsi.MinimumThreads < 1)
     throw new ArgumentOutOfRangeException("MinimumThreads", tpsi.MinimumThreads, "cannot be less than one");
   if (tpsi.MaximumThreads < 1)
     throw new ArgumentOutOfRangeException("MaximumThreads", tpsi.MaximumThreads, "cannot be less than one");
   if (tpsi.MinimumThreads > tpsi.MaximumThreads)
     throw new ArgumentOutOfRangeException("MinimumThreads", tpsi.MinimumThreads, "must be less or equal to MaximumThreads");
   if (tpsi.ThreadIdleTimeout < 0)
     throw new ArgumentOutOfRangeException("ThreadIdleTimeout", tpsi.ThreadIdleTimeout, "cannot be less than zero");
 }