1
0

STPStartInfo.cs 6.5 KB

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