WIGStartInfo.cs 4.3 KB

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