5 // Jérémie "Garuma" Laval <jeremie.laval@gmail.com>
6 // Marek Safar <marek.safar@gmail.com>
8 // Copyright (c) 2009 Jérémie "Garuma" Laval
9 // Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
11 // Permission is hereby granted, free of charge, to any person obtaining a copy
12 // of this software and associated documentation files (the "Software"), to deal
13 // in the Software without restriction, including without limitation the rights
14 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 // copies of the Software, and to permit persons to whom the Software is
16 // furnished to do so, subject to the following conditions:
18 // The above copyright notice and this permission notice shall be included in
19 // all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 using System.Threading;
34 namespace System.Threading.Tasks
37 public class TaskFactory
39 readonly TaskScheduler scheduler;
40 TaskCreationOptions creationOptions;
41 TaskContinuationOptions continuationOptions;
42 CancellationToken cancellationToken;
45 : this (CancellationToken.None, TaskCreationOptions.None, TaskContinuationOptions.None, null)
49 public TaskFactory (CancellationToken cancellationToken)
50 : this (cancellationToken, TaskCreationOptions.None, TaskContinuationOptions.None, null)
54 public TaskFactory (TaskScheduler scheduler)
55 : this (CancellationToken.None, TaskCreationOptions.None, TaskContinuationOptions.None, scheduler)
59 public TaskFactory (TaskCreationOptions creationOptions, TaskContinuationOptions continuationOptions)
60 : this (CancellationToken.None, creationOptions, continuationOptions, null)
64 public TaskFactory (CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskContinuationOptions continuationOptions,
65 TaskScheduler scheduler)
67 this.cancellationToken = cancellationToken;
68 this.scheduler = scheduler;
69 this.creationOptions = creationOptions;
70 this.continuationOptions = continuationOptions;
72 CheckContinuationOptions (continuationOptions);
75 public TaskScheduler Scheduler {
81 public TaskContinuationOptions ContinuationOptions {
83 return continuationOptions;
87 public TaskCreationOptions CreationOptions {
89 return creationOptions;
93 public CancellationToken CancellationToken {
95 return cancellationToken;
99 internal static void CheckContinuationOptions (TaskContinuationOptions continuationOptions)
101 if ((continuationOptions & (TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.NotOnRanToCompletion)) != 0)
102 throw new ArgumentOutOfRangeException ("continuationOptions");
104 const TaskContinuationOptions long_running = TaskContinuationOptions.LongRunning | TaskContinuationOptions.ExecuteSynchronously;
105 if ((continuationOptions & long_running) == long_running)
106 throw new ArgumentOutOfRangeException ("continuationOptions", "Synchronous continuations cannot be long running");
109 #region StartNew for Task
110 public Task StartNew (Action action)
112 return StartNew (action, cancellationToken, creationOptions, GetScheduler ());
115 public Task StartNew (Action action, CancellationToken cancellationToken)
117 return StartNew (action, cancellationToken, creationOptions, GetScheduler ());
120 public Task StartNew (Action action, TaskCreationOptions creationOptions)
122 return StartNew (action, cancellationToken, creationOptions, GetScheduler ());
125 public Task StartNew (Action<object> action, object state)
127 return StartNew (action, state, cancellationToken, creationOptions, GetScheduler ());
130 public Task StartNew (Action<object> action, object state, CancellationToken cancellationToken)
132 return StartNew (action, state, cancellationToken, creationOptions, GetScheduler ());
135 public Task StartNew (Action<object> action, object state, TaskCreationOptions creationOptions)
137 return StartNew (action, state, cancellationToken, creationOptions, GetScheduler ());
140 public Task StartNew (Action action, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler)
142 Task t = new Task (action, cancellationToken, creationOptions);
148 public Task StartNew (Action<object> action, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions,
149 TaskScheduler scheduler)
151 Task t = new Task (action, state, cancellationToken, creationOptions);
158 #region StartNew for Task<TResult>
159 public Task<TResult> StartNew<TResult> (Func<TResult> function)
161 return StartNew<TResult> (function, cancellationToken, creationOptions, GetScheduler ());
164 public Task<TResult> StartNew<TResult> (Func<TResult> function, TaskCreationOptions creationOptions)
166 return StartNew<TResult> (function, cancellationToken, creationOptions, GetScheduler ());
170 public Task<TResult> StartNew<TResult> (Func<TResult> function, CancellationToken cancellationToken)
172 return StartNew<TResult> (function, cancellationToken, creationOptions, GetScheduler ());
175 public Task<TResult> StartNew<TResult> (Func<TResult> function,
176 CancellationToken cancellationToken,
177 TaskCreationOptions creationOptions,
178 TaskScheduler scheduler)
180 return StartNew<TResult> ((o) => function (), null, cancellationToken, creationOptions, scheduler);
183 public Task<TResult> StartNew<TResult> (Func<object, TResult> function, object state)
185 return StartNew<TResult> (function, state, cancellationToken, creationOptions, GetScheduler ());
188 public Task<TResult> StartNew<TResult> (Func<object, TResult> function, object state, CancellationToken cancellationToken)
190 return StartNew<TResult> (function, state, cancellationToken, creationOptions, GetScheduler ());
193 public Task<TResult> StartNew<TResult> (Func<object, TResult> function, object state, TaskCreationOptions creationOptions)
195 return StartNew<TResult> (function, state, cancellationToken, creationOptions, GetScheduler ());
198 public Task<TResult> StartNew<TResult> (Func<object, TResult> function, object state,
199 CancellationToken cancellationToken,
200 TaskCreationOptions creationOptions,
201 TaskScheduler scheduler)
203 Task<TResult> t = new Task<TResult> (function, state, cancellationToken, creationOptions);
212 public Task ContinueWhenAny (Task[] tasks, Action<Task> continuationAction)
214 return ContinueWhenAny (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
217 public Task ContinueWhenAny (Task[] tasks, Action<Task> continuationAction, CancellationToken cancellationToken)
219 return ContinueWhenAny (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
222 public Task ContinueWhenAny (Task[] tasks, Action<Task> continuationAction, TaskContinuationOptions continuationOptions)
224 return ContinueWhenAny (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
227 public Task ContinueWhenAny (Task[] tasks,
228 Action<Task> continuationAction,
229 CancellationToken cancellationToken,
230 TaskContinuationOptions continuationOptions,
231 TaskScheduler scheduler)
233 var ourTasks = (Task[])tasks.Clone ();
234 AtomicBoolean trigger = new AtomicBoolean ();
235 var commonContinuation = new TaskCompletionSource<object> ();
236 Action<Task> continuationFunc = t => commonContinuation.SetResult (null);
238 foreach (Task t in ourTasks) {
239 Task cont = new Task ((o) => continuationAction ((Task)o), t, cancellationToken, creationOptions, t);
240 t.ContinueWithCore (cont, continuationOptions, scheduler, trigger.TrySet);
241 cont.ContinueWith (continuationFunc);
244 return commonContinuation.Task;
247 public Task ContinueWhenAny<TAntecedentResult> (Task<TAntecedentResult>[] tasks,
248 Action<Task<TAntecedentResult>> continuationAction)
250 return ContinueWhenAny (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
253 public Task ContinueWhenAny<TAntecedentResult> (Task<TAntecedentResult>[] tasks,
254 Action<Task<TAntecedentResult>> continuationAction,
255 CancellationToken cancellationToken)
257 return ContinueWhenAny (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
260 public Task ContinueWhenAny<TAntecedentResult> (Task<TAntecedentResult>[] tasks,
261 Action<Task<TAntecedentResult>> continuationAction,
262 TaskContinuationOptions continuationOptions)
264 return ContinueWhenAny (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
267 public Task ContinueWhenAny<TAntecedentResult> (Task<TAntecedentResult>[] tasks,
268 Action<Task<TAntecedentResult>> continuationAction,
269 CancellationToken cancellationToken,
270 TaskContinuationOptions continuationOptions,
271 TaskScheduler scheduler)
273 return ContinueWhenAny ((Task[]) tasks,
274 (o) => continuationAction ((Task<TAntecedentResult>)o),
275 cancellationToken, continuationOptions, scheduler);
278 public Task<TResult> ContinueWhenAny<TResult> (Task[] tasks, Func<Task, TResult> continuationFunction)
280 return ContinueWhenAny (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
283 public Task<TResult> ContinueWhenAny<TResult> (Task[] tasks,
284 Func<Task, TResult> continuationFunction,
285 CancellationToken cancellationToken)
287 return ContinueWhenAny (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
290 public Task<TResult> ContinueWhenAny<TResult> (Task[] tasks,
291 Func<Task, TResult> continuationFunction,
292 TaskContinuationOptions continuationOptions)
294 return ContinueWhenAny (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
297 public Task<TResult> ContinueWhenAny<TResult> (Task[] tasks,
298 Func<Task, TResult> continuationFunction,
299 CancellationToken cancellationToken,
300 TaskContinuationOptions continuationOptions,
301 TaskScheduler scheduler)
303 var ourTasks = (Task[])tasks.Clone ();
304 AtomicBoolean trigger = new AtomicBoolean ();
305 TaskCompletionSource<TResult> source = new TaskCompletionSource<TResult> ();
307 foreach (Task t in ourTasks) {
308 Task cont = new Task ((o) => source.SetResult (continuationFunction ((Task)o)), t, cancellationToken, creationOptions, t);
309 t.ContinueWithCore (cont, continuationOptions, scheduler, trigger.TrySet);
315 public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
316 Func<Task<TAntecedentResult>, TResult> continuationFunction)
318 return ContinueWhenAny (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
321 public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
322 Func<Task<TAntecedentResult>, TResult> continuationFunction,
323 CancellationToken cancellationToken)
325 return ContinueWhenAny (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
328 public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
329 Func<Task<TAntecedentResult>, TResult> continuationFunction,
330 TaskContinuationOptions continuationOptions)
332 return ContinueWhenAny (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
335 public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
336 Func<Task<TAntecedentResult>, TResult> continuationFunction,
337 CancellationToken cancellationToken,
338 TaskContinuationOptions continuationOptions,
339 TaskScheduler scheduler)
341 return ContinueWhenAny<TResult> ((Task[])tasks,
342 (t) => continuationFunction((Task<TAntecedentResult>)t),
348 public Task ContinueWhenAll (Task[] tasks, Action<Task[]> continuationAction)
350 return ContinueWhenAll (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
353 public Task ContinueWhenAll (Task[] tasks, Action<Task[]> continuationAction, CancellationToken cancellationToken)
355 return ContinueWhenAll (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
358 public Task ContinueWhenAll (Task[] tasks, Action<Task[]> continuationAction,
359 TaskContinuationOptions continuationOptions)
361 return ContinueWhenAll (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
364 public Task ContinueWhenAll (Task[] tasks, Action<Task[]> continuationAction, CancellationToken cancellationToken,
365 TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
367 var ourTasks = (Task[])tasks.Clone ();
368 CountdownEvent evt = new CountdownEvent (ourTasks.Length);
369 Task cont = new Task ((o) => continuationAction ((Task[])o), ourTasks, cancellationToken, creationOptions);
371 foreach (Task t in ourTasks)
372 t.ContinueWithCore (cont, continuationOptions, scheduler, evt.Signal);
377 public Task ContinueWhenAll<TAntecedentResult> (Task<TAntecedentResult>[] tasks,
378 Action<Task<TAntecedentResult>[]> continuationAction)
380 return ContinueWhenAll (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
383 public Task ContinueWhenAll<TAntecedentResult> (Task<TAntecedentResult>[] tasks,
384 Action<Task<TAntecedentResult>[]> continuationAction, CancellationToken cancellationToken)
386 return ContinueWhenAll (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
389 public Task ContinueWhenAll<TAntecedentResult> (Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>[]> continuationAction,
390 TaskContinuationOptions continuationOptions)
392 return ContinueWhenAll (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
395 public Task ContinueWhenAll<TAntecedentResult> (Task<TAntecedentResult>[] tasks,
396 Action<Task<TAntecedentResult>[]> continuationAction,
397 CancellationToken cancellationToken, TaskContinuationOptions continuationOptions,
398 TaskScheduler scheduler)
400 return ContinueWhenAll ((Task[]) tasks, (o) => continuationAction (tasks), cancellationToken,
401 continuationOptions, scheduler);
404 public Task<TResult> ContinueWhenAll<TResult> (Task[] tasks, Func<Task[], TResult> continuationFunction)
406 return ContinueWhenAll<TResult> (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
409 public Task<TResult> ContinueWhenAll<TResult> (Task[] tasks, Func<Task[], TResult> continuationFunction,
410 TaskContinuationOptions continuationOptions)
412 return ContinueWhenAll<TResult> (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
415 public Task<TResult> ContinueWhenAll<TResult> (Task[] tasks, Func<Task[], TResult> continuationFunction,
416 CancellationToken cancellationToken)
418 return ContinueWhenAll<TResult> (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
421 public Task<TResult> ContinueWhenAll<TResult> (Task[] tasks, Func<Task[], TResult> continuationFunction,
422 CancellationToken cancellationToken,
423 TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
425 var ourTasks = (Task[])tasks.Clone ();
426 CountdownEvent evt = new CountdownEvent (ourTasks.Length);
427 Task<TResult> cont = new Task<TResult> ((o) => continuationFunction ((Task[])o), ourTasks, cancellationToken, creationOptions);
429 foreach (Task t in ourTasks)
430 t.ContinueWithCore (cont, continuationOptions, scheduler, evt.Signal);
435 public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
436 Func<Task<TAntecedentResult>[], TResult> continuationFunction)
438 return ContinueWhenAll<TAntecedentResult, TResult> (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
441 public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
442 Func<Task<TAntecedentResult>[], TResult> continuationFunction,
443 TaskContinuationOptions continuationOptions)
445 return ContinueWhenAll<TAntecedentResult, TResult> (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
448 public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
449 Func<Task<TAntecedentResult>[], TResult> continuationFunction,
450 CancellationToken cancellationToken)
452 return ContinueWhenAll<TAntecedentResult, TResult> (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
455 public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
456 Func<Task<TAntecedentResult>[], TResult> continuationFunction,
457 CancellationToken cancellationToken,
458 TaskContinuationOptions continuationOptions,
459 TaskScheduler scheduler)
461 return ContinueWhenAll<TResult> ((Task[]) tasks,
462 (o) => continuationFunction (tasks),
464 continuationOptions, scheduler);
469 #region FromAsync IAsyncResult
471 public Task FromAsync (IAsyncResult asyncResult, Action<IAsyncResult> endMethod)
473 return FromAsync (asyncResult, endMethod, creationOptions);
476 public Task FromAsync (IAsyncResult asyncResult, Action<IAsyncResult> endMethod, TaskCreationOptions creationOptions)
478 return FromAsync (asyncResult, endMethod, creationOptions, GetScheduler ());
481 public Task FromAsync (IAsyncResult asyncResult, Action<IAsyncResult> endMethod, TaskCreationOptions creationOptions, TaskScheduler scheduler)
483 if (endMethod == null)
484 throw new ArgumentNullException ("endMethod");
486 return TaskFactory<object>.FromIAsyncResult (asyncResult,
488 endMethod (asyncResult);
490 }, creationOptions, scheduler);
493 public Task<TResult> FromAsync<TResult> (IAsyncResult asyncResult, Func<IAsyncResult, TResult> endMethod)
495 return FromAsync<TResult> (asyncResult, endMethod, creationOptions);
498 public Task<TResult> FromAsync<TResult> (IAsyncResult asyncResult, Func<IAsyncResult, TResult> endMethod, TaskCreationOptions creationOptions)
500 return FromAsync<TResult> (asyncResult, endMethod, creationOptions, GetScheduler ());
503 public Task<TResult> FromAsync<TResult> (IAsyncResult asyncResult, Func<IAsyncResult, TResult> endMethod, TaskCreationOptions creationOptions, TaskScheduler scheduler)
505 return TaskFactory<TResult>.FromIAsyncResult (asyncResult, endMethod, creationOptions, scheduler);
510 #region FromAsync Begin/End Method
512 public Task FromAsync (Func<AsyncCallback, object, IAsyncResult> beginMethod, Action<IAsyncResult> endMethod, object state)
514 return FromAsync (beginMethod, endMethod, state, creationOptions);
517 public Task FromAsync (Func<AsyncCallback, object, IAsyncResult> beginMethod, Action<IAsyncResult> endMethod,
518 object state, TaskCreationOptions creationOptions)
520 return TaskFactory<object>.FromAsyncBeginEnd (beginMethod,
521 l => { endMethod (l); return null; },
522 state, creationOptions);
525 public Task FromAsync<TArg1> (Func<TArg1, AsyncCallback, object, IAsyncResult> beginMethod, Action<IAsyncResult> endMethod,
526 TArg1 arg1, object state)
528 return FromAsync (beginMethod, endMethod, arg1, state, creationOptions);
531 public Task FromAsync<TArg1> (Func<TArg1, AsyncCallback, object, IAsyncResult> beginMethod, Action<IAsyncResult> endMethod,
532 TArg1 arg1, object state, TaskCreationOptions creationOptions)
534 if (endMethod == null)
535 throw new ArgumentNullException ("endMethod");
537 return TaskFactory<object>.FromAsyncBeginEnd (beginMethod,
538 l => { endMethod (l); return null; },
539 arg1, state, creationOptions);
542 public Task FromAsync<TArg1, TArg2> (Func<TArg1, TArg2, AsyncCallback, object, IAsyncResult> beginMethod,
543 Action<IAsyncResult> endMethod,
544 TArg1 arg1, TArg2 arg2, object state)
546 return FromAsync (beginMethod, endMethod, arg1, arg2, state, creationOptions);
549 public Task FromAsync<TArg1, TArg2> (Func<TArg1, TArg2, AsyncCallback, object, IAsyncResult> beginMethod,
550 Action<IAsyncResult> endMethod,
551 TArg1 arg1, TArg2 arg2, object state, TaskCreationOptions creationOptions)
553 if (endMethod == null)
554 throw new ArgumentNullException ("endMethod");
556 return TaskFactory<object>.FromAsyncBeginEnd (beginMethod,
557 l => { endMethod (l); return null; },
558 arg1, arg2, state, creationOptions);
561 public Task FromAsync<TArg1, TArg2, TArg3> (Func<TArg1, TArg2, TArg3, AsyncCallback, object, IAsyncResult> beginMethod, Action<IAsyncResult> endMethod,
562 TArg1 arg1, TArg2 arg2, TArg3 arg3, object state)
564 return FromAsync (beginMethod, endMethod, arg1, arg2, arg3, state, creationOptions);
567 public Task FromAsync<TArg1, TArg2, TArg3> (Func<TArg1, TArg2, TArg3, AsyncCallback, object, IAsyncResult> beginMethod, Action<IAsyncResult> endMethod,
568 TArg1 arg1, TArg2 arg2, TArg3 arg3, object state, TaskCreationOptions creationOptions)
570 if (endMethod == null)
571 throw new ArgumentNullException ("endMethod");
573 return TaskFactory<object>.FromAsyncBeginEnd (beginMethod,
574 l => { endMethod (l); return null; },
575 arg1, arg2, arg3, state, creationOptions);
578 public Task<TResult> FromAsync<TResult> (Func<AsyncCallback, object, IAsyncResult> beginMethod, Func<IAsyncResult, TResult> endMethod,
581 return FromAsync (beginMethod, endMethod, state, creationOptions);
584 public Task<TResult> FromAsync<TResult> (Func<AsyncCallback, object, IAsyncResult> beginMethod, Func<IAsyncResult, TResult> endMethod,
585 object state, TaskCreationOptions creationOptions)
587 return TaskFactory<TResult>.FromAsyncBeginEnd (beginMethod, endMethod, state, creationOptions);
590 public Task<TResult> FromAsync<TArg1, TResult> (Func<TArg1, AsyncCallback, object, IAsyncResult> beginMethod, Func<IAsyncResult, TResult> endMethod,
591 TArg1 arg1, object state)
593 return FromAsync (beginMethod, endMethod, arg1, state, creationOptions);
596 public Task<TResult> FromAsync<TArg1, TResult> (Func<TArg1, AsyncCallback, object, IAsyncResult> beginMethod, Func<IAsyncResult, TResult> endMethod,
597 TArg1 arg1, object state, TaskCreationOptions creationOptions)
599 return TaskFactory<TResult>.FromAsyncBeginEnd (beginMethod, endMethod, arg1, state, creationOptions);
602 public Task<TResult> FromAsync<TArg1, TArg2, TResult> (Func<TArg1, TArg2, AsyncCallback, object, IAsyncResult> beginMethod,
603 Func<IAsyncResult, TResult> endMethod,
604 TArg1 arg1, TArg2 arg2, object state)
606 return FromAsync (beginMethod, endMethod, arg1, arg2, state, creationOptions);
609 public Task<TResult> FromAsync<TArg1, TArg2, TResult> (Func<TArg1, TArg2, AsyncCallback, object, IAsyncResult> beginMethod, Func<IAsyncResult, TResult> endMethod,
610 TArg1 arg1, TArg2 arg2, object state, TaskCreationOptions creationOptions)
612 return TaskFactory<TResult>.FromAsyncBeginEnd (beginMethod, endMethod, arg1, arg2, state, creationOptions);
615 public Task<TResult> FromAsync<TArg1, TArg2, TArg3, TResult> (Func<TArg1, TArg2, TArg3, AsyncCallback, object, IAsyncResult> beginMethod, Func<IAsyncResult, TResult> endMethod,
616 TArg1 arg1, TArg2 arg2, TArg3 arg3, object state)
618 return FromAsync (beginMethod, endMethod, arg1, arg2, arg3, state, creationOptions);
621 public Task<TResult> FromAsync<TArg1, TArg2, TArg3, TResult> (Func<TArg1, TArg2, TArg3, AsyncCallback, object, IAsyncResult> beginMethod, Func<IAsyncResult, TResult> endMethod,
622 TArg1 arg1, TArg2 arg2, TArg3 arg3, object state, TaskCreationOptions creationOptions)
624 return TaskFactory<TResult>.FromAsyncBeginEnd (beginMethod, endMethod, arg1, arg2, arg3, state, creationOptions);
629 TaskScheduler GetScheduler ()
631 return scheduler ?? TaskScheduler.Current;