STPStartInfo.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using System;
  2. using System.Threading;
  3. namespace Amib.Threading
  4. {
  5. /// <summary>
  6. /// Summary description for STPStartInfo.
  7. /// </summary>
  8. public class STPStartInfo : WIGStartInfo
  9. {
  10. private int _idleTimeout = SmartThreadPool.DefaultIdleTimeout;
  11. private int _minWorkerThreads = SmartThreadPool.DefaultMinWorkerThreads;
  12. private int _maxWorkerThreads = SmartThreadPool.DefaultMaxWorkerThreads;
  13. private ThreadPriority _threadPriority = SmartThreadPool.DefaultThreadPriority;
  14. private bool _areThreadsBackground = SmartThreadPool.DefaultAreThreadsBackground;
  15. private string _threadPoolName = SmartThreadPool.DefaultThreadPoolName;
  16. private int? _maxStackSize = SmartThreadPool.DefaultMaxStackSize;
  17. private bool _supressflow = false;
  18. public STPStartInfo()
  19. {
  20. _threadPriority = SmartThreadPool.DefaultThreadPriority;
  21. _maxWorkerThreads = SmartThreadPool.DefaultMaxWorkerThreads;
  22. _idleTimeout = SmartThreadPool.DefaultIdleTimeout;
  23. _minWorkerThreads = SmartThreadPool.DefaultMinWorkerThreads;
  24. }
  25. public STPStartInfo(STPStartInfo stpStartInfo)
  26. : base(stpStartInfo)
  27. {
  28. _idleTimeout = stpStartInfo.IdleTimeout;
  29. _minWorkerThreads = stpStartInfo.MinWorkerThreads;
  30. _maxWorkerThreads = stpStartInfo.MaxWorkerThreads;
  31. _threadPriority = stpStartInfo.ThreadPriority;
  32. _threadPoolName = stpStartInfo._threadPoolName;
  33. _areThreadsBackground = stpStartInfo.AreThreadsBackground;
  34. _apartmentState = stpStartInfo._apartmentState;
  35. _supressflow = stpStartInfo._supressflow;
  36. }
  37. /// <summary>
  38. /// Get/Set the idle timeout in milliseconds.
  39. /// If a thread is idle (starved) longer than IdleTimeout then it may quit.
  40. /// </summary>
  41. public virtual int IdleTimeout
  42. {
  43. get { return _idleTimeout; }
  44. set
  45. {
  46. ThrowIfReadOnly();
  47. _idleTimeout = value;
  48. }
  49. }
  50. /// <summary>
  51. /// Get/Set the lower limit of threads in the pool.
  52. /// </summary>
  53. public virtual int MinWorkerThreads
  54. {
  55. get { return _minWorkerThreads; }
  56. set
  57. {
  58. ThrowIfReadOnly();
  59. _minWorkerThreads = value;
  60. }
  61. }
  62. /// <summary>
  63. /// Get/Set the upper limit of threads in the pool.
  64. /// </summary>
  65. public virtual int MaxWorkerThreads
  66. {
  67. get { return _maxWorkerThreads; }
  68. set
  69. {
  70. ThrowIfReadOnly();
  71. _maxWorkerThreads = value;
  72. }
  73. }
  74. /// <summary>
  75. /// Get/Set the scheduling priority of the threads in the pool.
  76. /// The Os handles the scheduling.
  77. /// </summary>
  78. public virtual ThreadPriority ThreadPriority
  79. {
  80. get { return _threadPriority; }
  81. set
  82. {
  83. ThrowIfReadOnly();
  84. _threadPriority = value;
  85. }
  86. }
  87. /// <summary>
  88. /// Get/Set the thread pool name. Threads will get names depending on this.
  89. /// </summary>
  90. public virtual string ThreadPoolName
  91. {
  92. get { return _threadPoolName; }
  93. set
  94. {
  95. ThrowIfReadOnly();
  96. _threadPoolName = value;
  97. }
  98. }
  99. /// <summary>
  100. /// Get/Set backgroundness of thread in thread pool.
  101. /// </summary>
  102. public virtual bool AreThreadsBackground
  103. {
  104. get { return _areThreadsBackground; }
  105. set
  106. {
  107. ThrowIfReadOnly();
  108. _areThreadsBackground = value;
  109. }
  110. }
  111. /// <summary>
  112. /// Get a readonly version of this STPStartInfo.
  113. /// </summary>
  114. /// <returns>Returns a readonly reference to this STPStartInfo</returns>
  115. public new STPStartInfo AsReadOnly()
  116. {
  117. return new STPStartInfo(this) { _readOnly = true };
  118. }
  119. private ApartmentState _apartmentState = SmartThreadPool.DefaultApartmentState;
  120. /// <summary>
  121. /// Get/Set the apartment state of threads in the thread pool
  122. /// </summary>
  123. public ApartmentState ApartmentState
  124. {
  125. get { return _apartmentState; }
  126. set
  127. {
  128. ThrowIfReadOnly();
  129. _apartmentState = value;
  130. }
  131. }
  132. /// <summary>
  133. /// Get/Set the max stack size of threads in the thread pool
  134. /// </summary>
  135. public int? MaxStackSize
  136. {
  137. get { return _maxStackSize; }
  138. set
  139. {
  140. ThrowIfReadOnly();
  141. if (value.HasValue && value.Value < 0)
  142. {
  143. throw new ArgumentOutOfRangeException("value", "Value must be greater than 0.");
  144. }
  145. _maxStackSize = value;
  146. }
  147. }
  148. public bool SuppressFlow
  149. {
  150. get { return _supressflow; }
  151. set
  152. {
  153. ThrowIfReadOnly();
  154. _supressflow = value;
  155. }
  156. }
  157. }
  158. }