STPStartInfo.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 string _performanceCounterInstanceName = SmartThreadPool.DefaultPerformanceCounterInstanceName;
  15. private bool _areThreadsBackground = SmartThreadPool.DefaultAreThreadsBackground;
  16. private bool _enableLocalPerformanceCounters;
  17. private string _threadPoolName = SmartThreadPool.DefaultThreadPoolName;
  18. private int? _maxStackSize = SmartThreadPool.DefaultMaxStackSize;
  19. private bool _supressflow = false;
  20. public STPStartInfo()
  21. {
  22. _performanceCounterInstanceName = SmartThreadPool.DefaultPerformanceCounterInstanceName;
  23. _threadPriority = SmartThreadPool.DefaultThreadPriority;
  24. _maxWorkerThreads = SmartThreadPool.DefaultMaxWorkerThreads;
  25. _idleTimeout = SmartThreadPool.DefaultIdleTimeout;
  26. _minWorkerThreads = SmartThreadPool.DefaultMinWorkerThreads;
  27. }
  28. public STPStartInfo(STPStartInfo stpStartInfo)
  29. : base(stpStartInfo)
  30. {
  31. _idleTimeout = stpStartInfo.IdleTimeout;
  32. _minWorkerThreads = stpStartInfo.MinWorkerThreads;
  33. _maxWorkerThreads = stpStartInfo.MaxWorkerThreads;
  34. _threadPriority = stpStartInfo.ThreadPriority;
  35. _performanceCounterInstanceName = stpStartInfo.PerformanceCounterInstanceName;
  36. _enableLocalPerformanceCounters = stpStartInfo._enableLocalPerformanceCounters;
  37. _threadPoolName = stpStartInfo._threadPoolName;
  38. _areThreadsBackground = stpStartInfo.AreThreadsBackground;
  39. _apartmentState = stpStartInfo._apartmentState;
  40. _supressflow = stpStartInfo._supressflow;
  41. }
  42. /// <summary>
  43. /// Get/Set the idle timeout in milliseconds.
  44. /// If a thread is idle (starved) longer than IdleTimeout then it may quit.
  45. /// </summary>
  46. public virtual int IdleTimeout
  47. {
  48. get { return _idleTimeout; }
  49. set
  50. {
  51. ThrowIfReadOnly();
  52. _idleTimeout = value;
  53. }
  54. }
  55. /// <summary>
  56. /// Get/Set the lower limit of threads in the pool.
  57. /// </summary>
  58. public virtual int MinWorkerThreads
  59. {
  60. get { return _minWorkerThreads; }
  61. set
  62. {
  63. ThrowIfReadOnly();
  64. _minWorkerThreads = value;
  65. }
  66. }
  67. /// <summary>
  68. /// Get/Set the upper limit of threads in the pool.
  69. /// </summary>
  70. public virtual int MaxWorkerThreads
  71. {
  72. get { return _maxWorkerThreads; }
  73. set
  74. {
  75. ThrowIfReadOnly();
  76. _maxWorkerThreads = value;
  77. }
  78. }
  79. /// <summary>
  80. /// Get/Set the scheduling priority of the threads in the pool.
  81. /// The Os handles the scheduling.
  82. /// </summary>
  83. public virtual ThreadPriority ThreadPriority
  84. {
  85. get { return _threadPriority; }
  86. set
  87. {
  88. ThrowIfReadOnly();
  89. _threadPriority = value;
  90. }
  91. }
  92. /// <summary>
  93. /// Get/Set the thread pool name. Threads will get names depending on this.
  94. /// </summary>
  95. public virtual string ThreadPoolName
  96. {
  97. get { return _threadPoolName; }
  98. set
  99. {
  100. ThrowIfReadOnly();
  101. _threadPoolName = value;
  102. }
  103. }
  104. /// <summary>
  105. /// Get/Set the performance counter instance name of this SmartThreadPool
  106. /// The default is null which indicate not to use performance counters at all.
  107. /// </summary>
  108. public virtual string PerformanceCounterInstanceName
  109. {
  110. get { return _performanceCounterInstanceName; }
  111. set
  112. {
  113. ThrowIfReadOnly();
  114. _performanceCounterInstanceName = value;
  115. }
  116. }
  117. /// <summary>
  118. /// Enable/Disable the local performance counter.
  119. /// This enables the user to get some performance information about the SmartThreadPool
  120. /// without using Windows performance counters. (Useful on WindowsCE, Silverlight, etc.)
  121. /// The default is false.
  122. /// </summary>
  123. public virtual bool EnableLocalPerformanceCounters
  124. {
  125. get { return _enableLocalPerformanceCounters; }
  126. set
  127. {
  128. ThrowIfReadOnly();
  129. _enableLocalPerformanceCounters = value;
  130. }
  131. }
  132. /// <summary>
  133. /// Get/Set backgroundness of thread in thread pool.
  134. /// </summary>
  135. public virtual bool AreThreadsBackground
  136. {
  137. get { return _areThreadsBackground; }
  138. set
  139. {
  140. ThrowIfReadOnly();
  141. _areThreadsBackground = value;
  142. }
  143. }
  144. /// <summary>
  145. /// Get a readonly version of this STPStartInfo.
  146. /// </summary>
  147. /// <returns>Returns a readonly reference to this STPStartInfo</returns>
  148. public new STPStartInfo AsReadOnly()
  149. {
  150. return new STPStartInfo(this) { _readOnly = true };
  151. }
  152. private ApartmentState _apartmentState = SmartThreadPool.DefaultApartmentState;
  153. /// <summary>
  154. /// Get/Set the apartment state of threads in the thread pool
  155. /// </summary>
  156. public ApartmentState ApartmentState
  157. {
  158. get { return _apartmentState; }
  159. set
  160. {
  161. ThrowIfReadOnly();
  162. _apartmentState = value;
  163. }
  164. }
  165. /// <summary>
  166. /// Get/Set the max stack size of threads in the thread pool
  167. /// </summary>
  168. public int? MaxStackSize
  169. {
  170. get { return _maxStackSize; }
  171. set
  172. {
  173. ThrowIfReadOnly();
  174. if (value.HasValue && value.Value < 0)
  175. {
  176. throw new ArgumentOutOfRangeException("value", "Value must be greater than 0.");
  177. }
  178. _maxStackSize = value;
  179. }
  180. }
  181. public bool SuppressFlow
  182. {
  183. get { return _supressflow; }
  184. set
  185. {
  186. ThrowIfReadOnly();
  187. _supressflow = value;
  188. }
  189. }
  190. }
  191. }