WIGStartInfo.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System;
  2. namespace Amib.Threading
  3. {
  4. /// <summary>
  5. /// Summary description for WIGStartInfo.
  6. /// </summary>
  7. public class WIGStartInfo
  8. {
  9. private bool _useCallerCallContext;
  10. private bool _useCallerHttpContext;
  11. private bool _disposeOfStateObjects;
  12. private CallToPostExecute _callToPostExecute;
  13. private PostExecuteWorkItemCallback _postExecuteWorkItemCallback;
  14. private bool _startSuspended;
  15. private WorkItemPriority _workItemPriority;
  16. private bool _fillStateWithArgs;
  17. protected bool _readOnly;
  18. public WIGStartInfo()
  19. {
  20. _fillStateWithArgs = SmartThreadPool.DefaultFillStateWithArgs;
  21. _workItemPriority = SmartThreadPool.DefaultWorkItemPriority;
  22. _startSuspended = SmartThreadPool.DefaultStartSuspended;
  23. _postExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback;
  24. _callToPostExecute = SmartThreadPool.DefaultCallToPostExecute;
  25. _disposeOfStateObjects = SmartThreadPool.DefaultDisposeOfStateObjects;
  26. _useCallerHttpContext = SmartThreadPool.DefaultUseCallerHttpContext;
  27. _useCallerCallContext = SmartThreadPool.DefaultUseCallerCallContext;
  28. }
  29. public WIGStartInfo(WIGStartInfo wigStartInfo)
  30. {
  31. _useCallerCallContext = wigStartInfo.UseCallerCallContext;
  32. _useCallerHttpContext = wigStartInfo.UseCallerHttpContext;
  33. _disposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
  34. _callToPostExecute = wigStartInfo.CallToPostExecute;
  35. _postExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback;
  36. _workItemPriority = wigStartInfo.WorkItemPriority;
  37. _startSuspended = wigStartInfo.StartSuspended;
  38. _fillStateWithArgs = wigStartInfo.FillStateWithArgs;
  39. }
  40. protected void ThrowIfReadOnly()
  41. {
  42. if (_readOnly)
  43. {
  44. throw new NotSupportedException("This is a readonly instance and set is not supported");
  45. }
  46. }
  47. /// <summary>
  48. /// Get/Set if to use the caller's security context
  49. /// </summary>
  50. public virtual bool UseCallerCallContext
  51. {
  52. get { return _useCallerCallContext; }
  53. set
  54. {
  55. ThrowIfReadOnly();
  56. _useCallerCallContext = value;
  57. }
  58. }
  59. /// <summary>
  60. /// Get/Set if to use the caller's HTTP context
  61. /// </summary>
  62. public virtual bool UseCallerHttpContext
  63. {
  64. get { return _useCallerHttpContext; }
  65. set
  66. {
  67. ThrowIfReadOnly();
  68. _useCallerHttpContext = value;
  69. }
  70. }
  71. /// <summary>
  72. /// Get/Set if to dispose of the state object of a work item
  73. /// </summary>
  74. public virtual bool DisposeOfStateObjects
  75. {
  76. get { return _disposeOfStateObjects; }
  77. set
  78. {
  79. ThrowIfReadOnly();
  80. _disposeOfStateObjects = value;
  81. }
  82. }
  83. /// <summary>
  84. /// Get/Set the run the post execute options
  85. /// </summary>
  86. public virtual CallToPostExecute CallToPostExecute
  87. {
  88. get { return _callToPostExecute; }
  89. set
  90. {
  91. ThrowIfReadOnly();
  92. _callToPostExecute = value;
  93. }
  94. }
  95. /// <summary>
  96. /// Get/Set the default post execute callback
  97. /// </summary>
  98. public virtual PostExecuteWorkItemCallback PostExecuteWorkItemCallback
  99. {
  100. get { return _postExecuteWorkItemCallback; }
  101. set
  102. {
  103. ThrowIfReadOnly();
  104. _postExecuteWorkItemCallback = value;
  105. }
  106. }
  107. /// <summary>
  108. /// Get/Set if the work items execution should be suspended until the Start()
  109. /// method is called.
  110. /// </summary>
  111. public virtual bool StartSuspended
  112. {
  113. get { return _startSuspended; }
  114. set
  115. {
  116. ThrowIfReadOnly();
  117. _startSuspended = value;
  118. }
  119. }
  120. /// <summary>
  121. /// Get/Set the default priority that a work item gets when it is enqueued
  122. /// </summary>
  123. public virtual WorkItemPriority WorkItemPriority
  124. {
  125. get { return _workItemPriority; }
  126. set { _workItemPriority = value; }
  127. }
  128. /// <summary>
  129. /// Get/Set the if QueueWorkItem of Action&lt;...&gt;/Func&lt;...&gt; fill the
  130. /// arguments as an object array into the state of the work item.
  131. /// The arguments can be access later by IWorkItemResult.State.
  132. /// </summary>
  133. public virtual bool FillStateWithArgs
  134. {
  135. get { return _fillStateWithArgs; }
  136. set
  137. {
  138. ThrowIfReadOnly();
  139. _fillStateWithArgs = value;
  140. }
  141. }
  142. /// <summary>
  143. /// Get a readonly version of this WIGStartInfo
  144. /// </summary>
  145. /// <returns>Returns a readonly reference to this WIGStartInfoRO</returns>
  146. public WIGStartInfo AsReadOnly()
  147. {
  148. return new WIGStartInfo(this) { _readOnly = true };
  149. }
  150. }
  151. }