WIGStartInfo.cs 4.8 KB

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