aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ThirdParty/SmartThreadPool/WorkItemsGroupBase.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ThirdParty/SmartThreadPool/WorkItemsGroupBase.cs940
1 files changed, 470 insertions, 470 deletions
diff --git a/ThirdParty/SmartThreadPool/WorkItemsGroupBase.cs b/ThirdParty/SmartThreadPool/WorkItemsGroupBase.cs
index 429de12..27fae5e 100644
--- a/ThirdParty/SmartThreadPool/WorkItemsGroupBase.cs
+++ b/ThirdParty/SmartThreadPool/WorkItemsGroupBase.cs
@@ -1,471 +1,471 @@
1using System; 1using System;
2using System.Threading; 2using System.Threading;
3 3
4namespace Amib.Threading.Internal 4namespace Amib.Threading.Internal
5{ 5{
6 public abstract class WorkItemsGroupBase : IWorkItemsGroup 6 public abstract class WorkItemsGroupBase : IWorkItemsGroup
7 { 7 {
8 #region Private Fields 8 #region Private Fields
9 9
10 /// <summary> 10 /// <summary>
11 /// Contains the name of this instance of SmartThreadPool. 11 /// Contains the name of this instance of SmartThreadPool.
12 /// Can be changed by the user. 12 /// Can be changed by the user.
13 /// </summary> 13 /// </summary>
14 private string _name = "WorkItemsGroupBase"; 14 private string _name = "WorkItemsGroupBase";
15 15
16 public WorkItemsGroupBase() 16 public WorkItemsGroupBase()
17 { 17 {
18 IsIdle = true; 18 IsIdle = true;
19 } 19 }
20 20
21 #endregion 21 #endregion
22 22
23 #region IWorkItemsGroup Members 23 #region IWorkItemsGroup Members
24 24
25 #region Public Methods 25 #region Public Methods
26 26
27 /// <summary> 27 /// <summary>
28 /// Get/Set the name of the SmartThreadPool/WorkItemsGroup instance 28 /// Get/Set the name of the SmartThreadPool/WorkItemsGroup instance
29 /// </summary> 29 /// </summary>
30 public string Name 30 public string Name
31 { 31 {
32 get { return _name; } 32 get { return _name; }
33 set { _name = value; } 33 set { _name = value; }
34 } 34 }
35 35
36 #endregion 36 #endregion
37 37
38 #region Abstract Methods 38 #region Abstract Methods
39 39
40 public abstract int Concurrency { get; set; } 40 public abstract int Concurrency { get; set; }
41 public abstract int WaitingCallbacks { get; } 41 public abstract int WaitingCallbacks { get; }
42 public abstract object[] GetStates(); 42 public abstract object[] GetStates();
43 public abstract WIGStartInfo WIGStartInfo { get; } 43 public abstract WIGStartInfo WIGStartInfo { get; }
44 public abstract void Start(); 44 public abstract void Start();
45 public abstract void Cancel(bool abortExecution); 45 public abstract void Cancel(bool abortExecution);
46 public abstract bool WaitForIdle(int millisecondsTimeout); 46 public abstract bool WaitForIdle(int millisecondsTimeout);
47 public abstract event WorkItemsGroupIdleHandler OnIdle; 47 public abstract event WorkItemsGroupIdleHandler OnIdle;
48 48
49 internal abstract void Enqueue(WorkItem workItem); 49 internal abstract void Enqueue(WorkItem workItem);
50 internal virtual void PreQueueWorkItem() { } 50 internal virtual void PreQueueWorkItem() { }
51 51
52 #endregion 52 #endregion
53 53
54 #region Common Base Methods 54 #region Common Base Methods
55 55
56 /// <summary> 56 /// <summary>
57 /// Cancel all the work items. 57 /// Cancel all the work items.
58 /// Same as Cancel(false) 58 /// Same as Cancel(false)
59 /// </summary> 59 /// </summary>
60 public virtual void Cancel() 60 public virtual void Cancel()
61 { 61 {
62 Cancel(false); 62 Cancel(false);
63 } 63 }
64 64
65 /// <summary> 65 /// <summary>
66 /// Wait for the SmartThreadPool/WorkItemsGroup to be idle 66 /// Wait for the SmartThreadPool/WorkItemsGroup to be idle
67 /// </summary> 67 /// </summary>
68 public void WaitForIdle() 68 public void WaitForIdle()
69 { 69 {
70 WaitForIdle(Timeout.Infinite); 70 WaitForIdle(Timeout.Infinite);
71 } 71 }
72 72
73 /// <summary> 73 /// <summary>
74 /// Wait for the SmartThreadPool/WorkItemsGroup to be idle 74 /// Wait for the SmartThreadPool/WorkItemsGroup to be idle
75 /// </summary> 75 /// </summary>
76 public bool WaitForIdle(TimeSpan timeout) 76 public bool WaitForIdle(TimeSpan timeout)
77 { 77 {
78 return WaitForIdle((int)timeout.TotalMilliseconds); 78 return WaitForIdle((int)timeout.TotalMilliseconds);
79 } 79 }
80 80
81 /// <summary> 81 /// <summary>
82 /// IsIdle is true when there are no work items running or queued. 82 /// IsIdle is true when there are no work items running or queued.
83 /// </summary> 83 /// </summary>
84 public bool IsIdle { get; protected set; } 84 public bool IsIdle { get; protected set; }
85 85
86 #endregion 86 #endregion
87 87
88 #region QueueWorkItem 88 #region QueueWorkItem
89 89
90 /// <summary> 90 /// <summary>
91 /// Queue a work item 91 /// Queue a work item
92 /// </summary> 92 /// </summary>
93 /// <param name="callback">A callback to execute</param> 93 /// <param name="callback">A callback to execute</param>
94 /// <returns>Returns a work item result</returns> 94 /// <returns>Returns a work item result</returns>
95 public IWorkItemResult QueueWorkItem(WorkItemCallback callback) 95 public IWorkItemResult QueueWorkItem(WorkItemCallback callback)
96 { 96 {
97 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback); 97 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback);
98 Enqueue(workItem); 98 Enqueue(workItem);
99 return workItem.GetWorkItemResult(); 99 return workItem.GetWorkItemResult();
100 } 100 }
101 101
102 /// <summary> 102 /// <summary>
103 /// Queue a work item 103 /// Queue a work item
104 /// </summary> 104 /// </summary>
105 /// <param name="callback">A callback to execute</param> 105 /// <param name="callback">A callback to execute</param>
106 /// <param name="workItemPriority">The priority of the work item</param> 106 /// <param name="workItemPriority">The priority of the work item</param>
107 /// <returns>Returns a work item result</returns> 107 /// <returns>Returns a work item result</returns>
108 public IWorkItemResult QueueWorkItem(WorkItemCallback callback, WorkItemPriority workItemPriority) 108 public IWorkItemResult QueueWorkItem(WorkItemCallback callback, WorkItemPriority workItemPriority)
109 { 109 {
110 PreQueueWorkItem(); 110 PreQueueWorkItem();
111 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, workItemPriority); 111 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, workItemPriority);
112 Enqueue(workItem); 112 Enqueue(workItem);
113 return workItem.GetWorkItemResult(); 113 return workItem.GetWorkItemResult();
114 } 114 }
115 115
116 /// <summary> 116 /// <summary>
117 /// Queue a work item 117 /// Queue a work item
118 /// </summary> 118 /// </summary>
119 /// <param name="workItemInfo">Work item info</param> 119 /// <param name="workItemInfo">Work item info</param>
120 /// <param name="callback">A callback to execute</param> 120 /// <param name="callback">A callback to execute</param>
121 /// <returns>Returns a work item result</returns> 121 /// <returns>Returns a work item result</returns>
122 public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback) 122 public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback)
123 { 123 {
124 PreQueueWorkItem(); 124 PreQueueWorkItem();
125 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, workItemInfo, callback); 125 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, workItemInfo, callback);
126 Enqueue(workItem); 126 Enqueue(workItem);
127 return workItem.GetWorkItemResult(); 127 return workItem.GetWorkItemResult();
128 } 128 }
129 129
130 /// <summary> 130 /// <summary>
131 /// Queue a work item 131 /// Queue a work item
132 /// </summary> 132 /// </summary>
133 /// <param name="callback">A callback to execute</param> 133 /// <param name="callback">A callback to execute</param>
134 /// <param name="state"> 134 /// <param name="state">
135 /// The context object of the work item. Used for passing arguments to the work item. 135 /// The context object of the work item. Used for passing arguments to the work item.
136 /// </param> 136 /// </param>
137 /// <returns>Returns a work item result</returns> 137 /// <returns>Returns a work item result</returns>
138 public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state) 138 public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state)
139 { 139 {
140 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state); 140 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state);
141 Enqueue(workItem); 141 Enqueue(workItem);
142 return workItem.GetWorkItemResult(); 142 return workItem.GetWorkItemResult();
143 } 143 }
144 144
145 /// <summary> 145 /// <summary>
146 /// Queue a work item 146 /// Queue a work item
147 /// </summary> 147 /// </summary>
148 /// <param name="callback">A callback to execute</param> 148 /// <param name="callback">A callback to execute</param>
149 /// <param name="state"> 149 /// <param name="state">
150 /// The context object of the work item. Used for passing arguments to the work item. 150 /// The context object of the work item. Used for passing arguments to the work item.
151 /// </param> 151 /// </param>
152 /// <param name="workItemPriority">The work item priority</param> 152 /// <param name="workItemPriority">The work item priority</param>
153 /// <returns>Returns a work item result</returns> 153 /// <returns>Returns a work item result</returns>
154 public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, WorkItemPriority workItemPriority) 154 public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, WorkItemPriority workItemPriority)
155 { 155 {
156 PreQueueWorkItem(); 156 PreQueueWorkItem();
157 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, workItemPriority); 157 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, workItemPriority);
158 Enqueue(workItem); 158 Enqueue(workItem);
159 return workItem.GetWorkItemResult(); 159 return workItem.GetWorkItemResult();
160 } 160 }
161 161
162 /// <summary> 162 /// <summary>
163 /// Queue a work item 163 /// Queue a work item
164 /// </summary> 164 /// </summary>
165 /// <param name="workItemInfo">Work item information</param> 165 /// <param name="workItemInfo">Work item information</param>
166 /// <param name="callback">A callback to execute</param> 166 /// <param name="callback">A callback to execute</param>
167 /// <param name="state"> 167 /// <param name="state">
168 /// The context object of the work item. Used for passing arguments to the work item. 168 /// The context object of the work item. Used for passing arguments to the work item.
169 /// </param> 169 /// </param>
170 /// <returns>Returns a work item result</returns> 170 /// <returns>Returns a work item result</returns>
171 public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback, object state) 171 public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback, object state)
172 { 172 {
173 PreQueueWorkItem(); 173 PreQueueWorkItem();
174 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, workItemInfo, callback, state); 174 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, workItemInfo, callback, state);
175 Enqueue(workItem); 175 Enqueue(workItem);
176 return workItem.GetWorkItemResult(); 176 return workItem.GetWorkItemResult();
177 } 177 }
178 178
179 /// <summary> 179 /// <summary>
180 /// Queue a work item 180 /// Queue a work item
181 /// </summary> 181 /// </summary>
182 /// <param name="callback">A callback to execute</param> 182 /// <param name="callback">A callback to execute</param>
183 /// <param name="state"> 183 /// <param name="state">
184 /// The context object of the work item. Used for passing arguments to the work item. 184 /// The context object of the work item. Used for passing arguments to the work item.
185 /// </param> 185 /// </param>
186 /// <param name="postExecuteWorkItemCallback"> 186 /// <param name="postExecuteWorkItemCallback">
187 /// A delegate to call after the callback completion 187 /// A delegate to call after the callback completion
188 /// </param> 188 /// </param>
189 /// <returns>Returns a work item result</returns> 189 /// <returns>Returns a work item result</returns>
190 public IWorkItemResult QueueWorkItem( 190 public IWorkItemResult QueueWorkItem(
191 WorkItemCallback callback, 191 WorkItemCallback callback,
192 object state, 192 object state,
193 PostExecuteWorkItemCallback postExecuteWorkItemCallback) 193 PostExecuteWorkItemCallback postExecuteWorkItemCallback)
194 { 194 {
195 PreQueueWorkItem(); 195 PreQueueWorkItem();
196 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback); 196 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback);
197 Enqueue(workItem); 197 Enqueue(workItem);
198 return workItem.GetWorkItemResult(); 198 return workItem.GetWorkItemResult();
199 } 199 }
200 200
201 /// <summary> 201 /// <summary>
202 /// Queue a work item 202 /// Queue a work item
203 /// </summary> 203 /// </summary>
204 /// <param name="callback">A callback to execute</param> 204 /// <param name="callback">A callback to execute</param>
205 /// <param name="state"> 205 /// <param name="state">
206 /// The context object of the work item. Used for passing arguments to the work item. 206 /// The context object of the work item. Used for passing arguments to the work item.
207 /// </param> 207 /// </param>
208 /// <param name="postExecuteWorkItemCallback"> 208 /// <param name="postExecuteWorkItemCallback">
209 /// A delegate to call after the callback completion 209 /// A delegate to call after the callback completion
210 /// </param> 210 /// </param>
211 /// <param name="workItemPriority">The work item priority</param> 211 /// <param name="workItemPriority">The work item priority</param>
212 /// <returns>Returns a work item result</returns> 212 /// <returns>Returns a work item result</returns>
213 public IWorkItemResult QueueWorkItem( 213 public IWorkItemResult QueueWorkItem(
214 WorkItemCallback callback, 214 WorkItemCallback callback,
215 object state, 215 object state,
216 PostExecuteWorkItemCallback postExecuteWorkItemCallback, 216 PostExecuteWorkItemCallback postExecuteWorkItemCallback,
217 WorkItemPriority workItemPriority) 217 WorkItemPriority workItemPriority)
218 { 218 {
219 PreQueueWorkItem(); 219 PreQueueWorkItem();
220 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, workItemPriority); 220 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, workItemPriority);
221 Enqueue(workItem); 221 Enqueue(workItem);
222 return workItem.GetWorkItemResult(); 222 return workItem.GetWorkItemResult();
223 } 223 }
224 224
225 /// <summary> 225 /// <summary>
226 /// Queue a work item 226 /// Queue a work item
227 /// </summary> 227 /// </summary>
228 /// <param name="callback">A callback to execute</param> 228 /// <param name="callback">A callback to execute</param>
229 /// <param name="state"> 229 /// <param name="state">
230 /// The context object of the work item. Used for passing arguments to the work item. 230 /// The context object of the work item. Used for passing arguments to the work item.
231 /// </param> 231 /// </param>
232 /// <param name="postExecuteWorkItemCallback"> 232 /// <param name="postExecuteWorkItemCallback">
233 /// A delegate to call after the callback completion 233 /// A delegate to call after the callback completion
234 /// </param> 234 /// </param>
235 /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param> 235 /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param>
236 /// <returns>Returns a work item result</returns> 236 /// <returns>Returns a work item result</returns>
237 public IWorkItemResult QueueWorkItem( 237 public IWorkItemResult QueueWorkItem(
238 WorkItemCallback callback, 238 WorkItemCallback callback,
239 object state, 239 object state,
240 PostExecuteWorkItemCallback postExecuteWorkItemCallback, 240 PostExecuteWorkItemCallback postExecuteWorkItemCallback,
241 CallToPostExecute callToPostExecute) 241 CallToPostExecute callToPostExecute)
242 { 242 {
243 PreQueueWorkItem(); 243 PreQueueWorkItem();
244 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute); 244 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute);
245 Enqueue(workItem); 245 Enqueue(workItem);
246 return workItem.GetWorkItemResult(); 246 return workItem.GetWorkItemResult();
247 } 247 }
248 248
249 /// <summary> 249 /// <summary>
250 /// Queue a work item 250 /// Queue a work item
251 /// </summary> 251 /// </summary>
252 /// <param name="callback">A callback to execute</param> 252 /// <param name="callback">A callback to execute</param>
253 /// <param name="state"> 253 /// <param name="state">
254 /// The context object of the work item. Used for passing arguments to the work item. 254 /// The context object of the work item. Used for passing arguments to the work item.
255 /// </param> 255 /// </param>
256 /// <param name="postExecuteWorkItemCallback"> 256 /// <param name="postExecuteWorkItemCallback">
257 /// A delegate to call after the callback completion 257 /// A delegate to call after the callback completion
258 /// </param> 258 /// </param>
259 /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param> 259 /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param>
260 /// <param name="workItemPriority">The work item priority</param> 260 /// <param name="workItemPriority">The work item priority</param>
261 /// <returns>Returns a work item result</returns> 261 /// <returns>Returns a work item result</returns>
262 public IWorkItemResult QueueWorkItem( 262 public IWorkItemResult QueueWorkItem(
263 WorkItemCallback callback, 263 WorkItemCallback callback,
264 object state, 264 object state,
265 PostExecuteWorkItemCallback postExecuteWorkItemCallback, 265 PostExecuteWorkItemCallback postExecuteWorkItemCallback,
266 CallToPostExecute callToPostExecute, 266 CallToPostExecute callToPostExecute,
267 WorkItemPriority workItemPriority) 267 WorkItemPriority workItemPriority)
268 { 268 {
269 PreQueueWorkItem(); 269 PreQueueWorkItem();
270 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); 270 WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority);
271 Enqueue(workItem); 271 Enqueue(workItem);
272 return workItem.GetWorkItemResult(); 272 return workItem.GetWorkItemResult();
273 } 273 }
274 274
275 #endregion 275 #endregion
276 276
277 #region QueueWorkItem(Action<...>) 277 #region QueueWorkItem(Action<...>)
278 278
279 public IWorkItemResult QueueWorkItem(Action action) 279 public IWorkItemResult QueueWorkItem(Action action)
280 { 280 {
281 return QueueWorkItem (action, SmartThreadPool.DefaultWorkItemPriority); 281 return QueueWorkItem (action, SmartThreadPool.DefaultWorkItemPriority);
282 } 282 }
283 283
284 public IWorkItemResult QueueWorkItem (Action action, WorkItemPriority priority) 284 public IWorkItemResult QueueWorkItem (Action action, WorkItemPriority priority)
285 { 285 {
286 PreQueueWorkItem (); 286 PreQueueWorkItem ();
287 WorkItem workItem = WorkItemFactory.CreateWorkItem ( 287 WorkItem workItem = WorkItemFactory.CreateWorkItem (
288 this, 288 this,
289 WIGStartInfo, 289 WIGStartInfo,
290 delegate 290 delegate
291 { 291 {
292 action.Invoke (); 292 action.Invoke ();
293 return null; 293 return null;
294 }, priority); 294 }, priority);
295 Enqueue (workItem); 295 Enqueue (workItem);
296 return workItem.GetWorkItemResult (); 296 return workItem.GetWorkItemResult ();
297 } 297 }
298 298
299 public IWorkItemResult QueueWorkItem<T>(Action<T> action, T arg) 299 public IWorkItemResult QueueWorkItem<T>(Action<T> action, T arg)
300 { 300 {
301 return QueueWorkItem<T> (action, arg, SmartThreadPool.DefaultWorkItemPriority); 301 return QueueWorkItem<T> (action, arg, SmartThreadPool.DefaultWorkItemPriority);
302 } 302 }
303 303
304 public IWorkItemResult QueueWorkItem<T> (Action<T> action, T arg, WorkItemPriority priority) 304 public IWorkItemResult QueueWorkItem<T> (Action<T> action, T arg, WorkItemPriority priority)
305 { 305 {
306 PreQueueWorkItem (); 306 PreQueueWorkItem ();
307 WorkItem workItem = WorkItemFactory.CreateWorkItem ( 307 WorkItem workItem = WorkItemFactory.CreateWorkItem (
308 this, 308 this,
309 WIGStartInfo, 309 WIGStartInfo,
310 state => 310 state =>
311 { 311 {
312 action.Invoke (arg); 312 action.Invoke (arg);
313 return null; 313 return null;
314 }, 314 },
315 WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null, priority); 315 WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null, priority);
316 Enqueue (workItem); 316 Enqueue (workItem);
317 return workItem.GetWorkItemResult (); 317 return workItem.GetWorkItemResult ();
318 } 318 }
319 319
320 public IWorkItemResult QueueWorkItem<T1, T2>(Action<T1, T2> action, T1 arg1, T2 arg2) 320 public IWorkItemResult QueueWorkItem<T1, T2>(Action<T1, T2> action, T1 arg1, T2 arg2)
321 { 321 {
322 return QueueWorkItem<T1, T2> (action, arg1, arg2, SmartThreadPool.DefaultWorkItemPriority); 322 return QueueWorkItem<T1, T2> (action, arg1, arg2, SmartThreadPool.DefaultWorkItemPriority);
323 } 323 }
324 324
325 public IWorkItemResult QueueWorkItem<T1, T2> (Action<T1, T2> action, T1 arg1, T2 arg2, WorkItemPriority priority) 325 public IWorkItemResult QueueWorkItem<T1, T2> (Action<T1, T2> action, T1 arg1, T2 arg2, WorkItemPriority priority)
326 { 326 {
327 PreQueueWorkItem (); 327 PreQueueWorkItem ();
328 WorkItem workItem = WorkItemFactory.CreateWorkItem ( 328 WorkItem workItem = WorkItemFactory.CreateWorkItem (
329 this, 329 this,
330 WIGStartInfo, 330 WIGStartInfo,
331 state => 331 state =>
332 { 332 {
333 action.Invoke (arg1, arg2); 333 action.Invoke (arg1, arg2);
334 return null; 334 return null;
335 }, 335 },
336 WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null, priority); 336 WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null, priority);
337 Enqueue (workItem); 337 Enqueue (workItem);
338 return workItem.GetWorkItemResult (); 338 return workItem.GetWorkItemResult ();
339 } 339 }
340 340
341 public IWorkItemResult QueueWorkItem<T1, T2, T3>(Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3) 341 public IWorkItemResult QueueWorkItem<T1, T2, T3>(Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3)
342 { 342 {
343 return QueueWorkItem<T1, T2, T3> (action, arg1, arg2, arg3, SmartThreadPool.DefaultWorkItemPriority); 343 return QueueWorkItem<T1, T2, T3> (action, arg1, arg2, arg3, SmartThreadPool.DefaultWorkItemPriority);
344 ; 344 ;
345 } 345 }
346 346
347 public IWorkItemResult QueueWorkItem<T1, T2, T3> (Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3, WorkItemPriority priority) 347 public IWorkItemResult QueueWorkItem<T1, T2, T3> (Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3, WorkItemPriority priority)
348 { 348 {
349 PreQueueWorkItem (); 349 PreQueueWorkItem ();
350 WorkItem workItem = WorkItemFactory.CreateWorkItem ( 350 WorkItem workItem = WorkItemFactory.CreateWorkItem (
351 this, 351 this,
352 WIGStartInfo, 352 WIGStartInfo,
353 state => 353 state =>
354 { 354 {
355 action.Invoke (arg1, arg2, arg3); 355 action.Invoke (arg1, arg2, arg3);
356 return null; 356 return null;
357 }, 357 },
358 WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3 } : null, priority); 358 WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3 } : null, priority);
359 Enqueue (workItem); 359 Enqueue (workItem);
360 return workItem.GetWorkItemResult (); 360 return workItem.GetWorkItemResult ();
361 } 361 }
362 362
363 public IWorkItemResult QueueWorkItem<T1, T2, T3, T4>( 363 public IWorkItemResult QueueWorkItem<T1, T2, T3, T4>(
364 Action<T1, T2, T3, T4> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4) 364 Action<T1, T2, T3, T4> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
365 { 365 {
366 return QueueWorkItem<T1, T2, T3, T4> (action, arg1, arg2, arg3, arg4, 366 return QueueWorkItem<T1, T2, T3, T4> (action, arg1, arg2, arg3, arg4,
367 SmartThreadPool.DefaultWorkItemPriority); 367 SmartThreadPool.DefaultWorkItemPriority);
368 } 368 }
369 369
370 public IWorkItemResult QueueWorkItem<T1, T2, T3, T4> ( 370 public IWorkItemResult QueueWorkItem<T1, T2, T3, T4> (
371 Action<T1, T2, T3, T4> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, WorkItemPriority priority) 371 Action<T1, T2, T3, T4> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, WorkItemPriority priority)
372 { 372 {
373 PreQueueWorkItem (); 373 PreQueueWorkItem ();
374 WorkItem workItem = WorkItemFactory.CreateWorkItem ( 374 WorkItem workItem = WorkItemFactory.CreateWorkItem (
375 this, 375 this,
376 WIGStartInfo, 376 WIGStartInfo,
377 state => 377 state =>
378 { 378 {
379 action.Invoke (arg1, arg2, arg3, arg4); 379 action.Invoke (arg1, arg2, arg3, arg4);
380 return null; 380 return null;
381 }, 381 },
382 WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3, arg4 } : null, priority); 382 WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3, arg4 } : null, priority);
383 Enqueue (workItem); 383 Enqueue (workItem);
384 return workItem.GetWorkItemResult (); 384 return workItem.GetWorkItemResult ();
385 } 385 }
386 386
387 #endregion 387 #endregion
388 388
389 #region QueueWorkItem(Func<...>) 389 #region QueueWorkItem(Func<...>)
390 390
391 public IWorkItemResult<TResult> QueueWorkItem<TResult>(Func<TResult> func) 391 public IWorkItemResult<TResult> QueueWorkItem<TResult>(Func<TResult> func)
392 { 392 {
393 PreQueueWorkItem(); 393 PreQueueWorkItem();
394 WorkItem workItem = WorkItemFactory.CreateWorkItem( 394 WorkItem workItem = WorkItemFactory.CreateWorkItem(
395 this, 395 this,
396 WIGStartInfo, 396 WIGStartInfo,
397 state => 397 state =>
398 { 398 {
399 return func.Invoke(); 399 return func.Invoke();
400 }); 400 });
401 Enqueue(workItem); 401 Enqueue(workItem);
402 return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult()); 402 return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult());
403 } 403 }
404 404
405 public IWorkItemResult<TResult> QueueWorkItem<T, TResult>(Func<T, TResult> func, T arg) 405 public IWorkItemResult<TResult> QueueWorkItem<T, TResult>(Func<T, TResult> func, T arg)
406 { 406 {
407 PreQueueWorkItem(); 407 PreQueueWorkItem();
408 WorkItem workItem = WorkItemFactory.CreateWorkItem( 408 WorkItem workItem = WorkItemFactory.CreateWorkItem(
409 this, 409 this,
410 WIGStartInfo, 410 WIGStartInfo,
411 state => 411 state =>
412 { 412 {
413 return func.Invoke(arg); 413 return func.Invoke(arg);
414 }, 414 },
415 WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null); 415 WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null);
416 Enqueue(workItem); 416 Enqueue(workItem);
417 return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult()); 417 return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult());
418 } 418 }
419 419
420 public IWorkItemResult<TResult> QueueWorkItem<T1, T2, TResult>(Func<T1, T2, TResult> func, T1 arg1, T2 arg2) 420 public IWorkItemResult<TResult> QueueWorkItem<T1, T2, TResult>(Func<T1, T2, TResult> func, T1 arg1, T2 arg2)
421 { 421 {
422 PreQueueWorkItem(); 422 PreQueueWorkItem();
423 WorkItem workItem = WorkItemFactory.CreateWorkItem( 423 WorkItem workItem = WorkItemFactory.CreateWorkItem(
424 this, 424 this,
425 WIGStartInfo, 425 WIGStartInfo,
426 state => 426 state =>
427 { 427 {
428 return func.Invoke(arg1, arg2); 428 return func.Invoke(arg1, arg2);
429 }, 429 },
430 WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null); 430 WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null);
431 Enqueue(workItem); 431 Enqueue(workItem);
432 return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult()); 432 return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult());
433 } 433 }
434 434
435 public IWorkItemResult<TResult> QueueWorkItem<T1, T2, T3, TResult>( 435 public IWorkItemResult<TResult> QueueWorkItem<T1, T2, T3, TResult>(
436 Func<T1, T2, T3, TResult> func, T1 arg1, T2 arg2, T3 arg3) 436 Func<T1, T2, T3, TResult> func, T1 arg1, T2 arg2, T3 arg3)
437 { 437 {
438 PreQueueWorkItem(); 438 PreQueueWorkItem();
439 WorkItem workItem = WorkItemFactory.CreateWorkItem( 439 WorkItem workItem = WorkItemFactory.CreateWorkItem(
440 this, 440 this,
441 WIGStartInfo, 441 WIGStartInfo,
442 state => 442 state =>
443 { 443 {
444 return func.Invoke(arg1, arg2, arg3); 444 return func.Invoke(arg1, arg2, arg3);
445 }, 445 },
446 WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3 } : null); 446 WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3 } : null);
447 Enqueue(workItem); 447 Enqueue(workItem);
448 return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult()); 448 return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult());
449 } 449 }
450 450
451 public IWorkItemResult<TResult> QueueWorkItem<T1, T2, T3, T4, TResult>( 451 public IWorkItemResult<TResult> QueueWorkItem<T1, T2, T3, T4, TResult>(
452 Func<T1, T2, T3, T4, TResult> func, T1 arg1, T2 arg2, T3 arg3, T4 arg4) 452 Func<T1, T2, T3, T4, TResult> func, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
453 { 453 {
454 PreQueueWorkItem(); 454 PreQueueWorkItem();
455 WorkItem workItem = WorkItemFactory.CreateWorkItem( 455 WorkItem workItem = WorkItemFactory.CreateWorkItem(
456 this, 456 this,
457 WIGStartInfo, 457 WIGStartInfo,
458 state => 458 state =>
459 { 459 {
460 return func.Invoke(arg1, arg2, arg3, arg4); 460 return func.Invoke(arg1, arg2, arg3, arg4);
461 }, 461 },
462 WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3, arg4 } : null); 462 WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3, arg4 } : null);
463 Enqueue(workItem); 463 Enqueue(workItem);
464 return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult()); 464 return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult());
465 } 465 }
466 466
467 #endregion 467 #endregion
468 468
469 #endregion 469 #endregion
470 } 470 }
471} \ No newline at end of file 471} \ No newline at end of file