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
31 namespace System.Threading.Tasks
33 public class TaskFactory
35 readonly TaskScheduler scheduler;
36 TaskCreationOptions creationOptions;
37 TaskContinuationOptions continuationOptions;
38 CancellationToken cancellationToken;
41 : this (CancellationToken.None, TaskCreationOptions.None, TaskContinuationOptions.None, null)
45 public TaskFactory (CancellationToken cancellationToken)
46 : this (cancellationToken, TaskCreationOptions.None, TaskContinuationOptions.None, null)
50 public TaskFactory (TaskScheduler scheduler)
51 : this (CancellationToken.None, TaskCreationOptions.None, TaskContinuationOptions.None, scheduler)
55 public TaskFactory (TaskCreationOptions creationOptions, TaskContinuationOptions continuationOptions)
56 : this (CancellationToken.None, creationOptions, continuationOptions, null)
60 public TaskFactory (CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskContinuationOptions continuationOptions,
61 TaskScheduler scheduler)
63 this.cancellationToken = cancellationToken;
64 this.scheduler = scheduler;
65 this.creationOptions = creationOptions;
66 this.continuationOptions = continuationOptions;
68 CheckContinuationOptions (continuationOptions);
71 public TaskScheduler Scheduler {
77 public TaskContinuationOptions ContinuationOptions {
79 return continuationOptions;
83 public TaskCreationOptions CreationOptions {
85 return creationOptions;
89 public CancellationToken CancellationToken {
91 return cancellationToken;
95 internal static void CheckContinuationOptions (TaskContinuationOptions continuationOptions)
97 if ((continuationOptions & (TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.NotOnRanToCompletion)) != 0)
98 throw new ArgumentOutOfRangeException ("continuationOptions");
100 const TaskContinuationOptions long_running = TaskContinuationOptions.LongRunning | TaskContinuationOptions.ExecuteSynchronously;
101 if ((continuationOptions & long_running) == long_running)
102 throw new ArgumentOutOfRangeException ("continuationOptions", "Synchronous continuations cannot be long running");
105 #region StartNew for Task
106 public Task StartNew (Action action)
108 return StartNew (action, cancellationToken, creationOptions, GetScheduler ());
111 public Task StartNew (Action action, CancellationToken cancellationToken)
113 return StartNew (action, cancellationToken, creationOptions, GetScheduler ());
116 public Task StartNew (Action action, TaskCreationOptions creationOptions)
118 return StartNew (action, cancellationToken, creationOptions, GetScheduler ());
121 public Task StartNew (Action action, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler)
123 Task t = new Task (action, cancellationToken, creationOptions);
126 // Don't start cancelled task it would throw an exception
134 public Task StartNew (Action<object> action, object state)
136 return StartNew (action, state, cancellationToken, creationOptions, GetScheduler ());
139 public Task StartNew (Action<object> action, object state, CancellationToken cancellationToken)
141 return StartNew (action, state, cancellationToken, creationOptions, GetScheduler ());
144 public Task StartNew (Action<object> action, object state, TaskCreationOptions creationOptions)
146 return StartNew (action, state, cancellationToken, creationOptions, GetScheduler ());
149 public Task StartNew (Action<object> action, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions,
150 TaskScheduler scheduler)
152 Task t = new Task (action, state, cancellationToken, creationOptions);
155 // Don't start cancelled task it would throw an exception
164 #region StartNew for Task<TResult>
165 public Task<TResult> StartNew<TResult> (Func<TResult> function)
167 return StartNew<TResult> (function, cancellationToken, creationOptions, GetScheduler ());
170 public Task<TResult> StartNew<TResult> (Func<TResult> function, TaskCreationOptions creationOptions)
172 return StartNew<TResult> (function, cancellationToken, creationOptions, GetScheduler ());
176 public Task<TResult> StartNew<TResult> (Func<TResult> function, CancellationToken cancellationToken)
178 return StartNew<TResult> (function, cancellationToken, creationOptions, GetScheduler ());
181 public Task<TResult> StartNew<TResult> (Func<TResult> function,
182 CancellationToken cancellationToken,
183 TaskCreationOptions creationOptions,
184 TaskScheduler scheduler)
186 var t = new Task<TResult> (function, cancellationToken, creationOptions);
189 // Don't start cancelled task it would throw an exception
197 public Task<TResult> StartNew<TResult> (Func<object, TResult> function, object state)
199 return StartNew<TResult> (function, state, cancellationToken, creationOptions, GetScheduler ());
202 public Task<TResult> StartNew<TResult> (Func<object, TResult> function, object state, CancellationToken cancellationToken)
204 return StartNew<TResult> (function, state, cancellationToken, creationOptions, GetScheduler ());
207 public Task<TResult> StartNew<TResult> (Func<object, TResult> function, object state, TaskCreationOptions creationOptions)
209 return StartNew<TResult> (function, state, cancellationToken, creationOptions, GetScheduler ());
212 public Task<TResult> StartNew<TResult> (Func<object, TResult> function, object state,
213 CancellationToken cancellationToken,
214 TaskCreationOptions creationOptions,
215 TaskScheduler scheduler)
217 Task<TResult> t = new Task<TResult> (function, state, cancellationToken, creationOptions);
226 public Task ContinueWhenAny (Task[] tasks, Action<Task> continuationAction)
228 return ContinueWhenAny (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
231 public Task ContinueWhenAny (Task[] tasks, Action<Task> continuationAction, CancellationToken cancellationToken)
233 return ContinueWhenAny (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
236 public Task ContinueWhenAny (Task[] tasks, Action<Task> continuationAction, TaskContinuationOptions continuationOptions)
238 return ContinueWhenAny (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
241 public Task ContinueWhenAny (Task[] tasks, Action<Task> continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
244 throw new ArgumentNullException ("tasks");
246 if (tasks.Length == 0)
247 throw new ArgumentException ("The tasks argument contains no tasks", "tasks");
249 foreach (var ta in tasks) {
251 throw new ArgumentException ("The tasks argument constains a null value", "tasks");
254 if (continuationAction == null)
255 throw new ArgumentNullException ("continuationAction");
257 var t = new Task<int> (l => {
258 var data = (Tuple<Task[], CancellationToken>) l;
259 return Task.WaitAny (data.Item1, data.Item2);
260 }, Tuple.Create (tasks, cancellationToken));
262 var cont = t.ContinueWith (TaskActionInvoker.Create (continuationAction, tasks), cancellationToken, continuationOptions, scheduler);
269 public Task ContinueWhenAny<TAntecedentResult> (Task<TAntecedentResult>[] tasks,
270 Action<Task<TAntecedentResult>> continuationAction)
272 return ContinueWhenAny (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
275 public Task ContinueWhenAny<TAntecedentResult> (Task<TAntecedentResult>[] tasks,
276 Action<Task<TAntecedentResult>> continuationAction,
277 CancellationToken cancellationToken)
279 return ContinueWhenAny (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
282 public Task ContinueWhenAny<TAntecedentResult> (Task<TAntecedentResult>[] tasks,
283 Action<Task<TAntecedentResult>> continuationAction,
284 TaskContinuationOptions continuationOptions)
286 return ContinueWhenAny (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
289 public Task ContinueWhenAny<TAntecedentResult> (Task<TAntecedentResult>[] tasks,
290 Action<Task<TAntecedentResult>> continuationAction,
291 CancellationToken cancellationToken,
292 TaskContinuationOptions continuationOptions,
293 TaskScheduler scheduler)
295 return ContinueWhenAny ((Task[]) tasks,
296 (o) => continuationAction ((Task<TAntecedentResult>)o),
297 cancellationToken, continuationOptions, scheduler);
300 public Task<TResult> ContinueWhenAny<TResult> (Task[] tasks, Func<Task, TResult> continuationFunction)
302 return ContinueWhenAny (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
305 public Task<TResult> ContinueWhenAny<TResult> (Task[] tasks,
306 Func<Task, TResult> continuationFunction,
307 CancellationToken cancellationToken)
309 return ContinueWhenAny (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
312 public Task<TResult> ContinueWhenAny<TResult> (Task[] tasks,
313 Func<Task, TResult> continuationFunction,
314 TaskContinuationOptions continuationOptions)
316 return ContinueWhenAny (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
319 public Task<TResult> ContinueWhenAny<TResult> (Task[] tasks,
320 Func<Task, TResult> continuationFunction,
321 CancellationToken cancellationToken,
322 TaskContinuationOptions continuationOptions,
323 TaskScheduler scheduler)
325 var t = new Task<int> (l => {
326 var data = (Tuple<Task[], CancellationToken>) l;
327 return Task.WaitAny (data.Item1, data.Item2);
328 }, Tuple.Create (tasks, cancellationToken));
330 var cont = t.ContinueWith<TResult> (TaskActionInvoker.Create (continuationFunction, tasks), cancellationToken, continuationOptions, scheduler);
337 public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
338 Func<Task<TAntecedentResult>, TResult> continuationFunction)
340 return ContinueWhenAny (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
343 public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
344 Func<Task<TAntecedentResult>, TResult> continuationFunction,
345 CancellationToken cancellationToken)
347 return ContinueWhenAny (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
350 public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
351 Func<Task<TAntecedentResult>, TResult> continuationFunction,
352 TaskContinuationOptions continuationOptions)
354 return ContinueWhenAny (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
357 public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
358 Func<Task<TAntecedentResult>, TResult> continuationFunction,
359 CancellationToken cancellationToken,
360 TaskContinuationOptions continuationOptions,
361 TaskScheduler scheduler)
363 return ContinueWhenAny<TResult> ((Task[])tasks,
364 (t) => continuationFunction((Task<TAntecedentResult>)t),
370 public Task ContinueWhenAll (Task[] tasks, Action<Task[]> continuationAction)
372 return ContinueWhenAll (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
375 public Task ContinueWhenAll (Task[] tasks, Action<Task[]> continuationAction, CancellationToken cancellationToken)
377 return ContinueWhenAll (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
380 public Task ContinueWhenAll (Task[] tasks, Action<Task[]> continuationAction,
381 TaskContinuationOptions continuationOptions)
383 return ContinueWhenAll (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
386 public Task ContinueWhenAll (Task[] tasks, Action<Task[]> continuationAction, CancellationToken cancellationToken,
387 TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
389 var t = new Task (l => {
390 var data = (Tuple<Task[], CancellationToken>) l;
391 Task.WaitAll (data.Item1, data.Item2);
392 }, Tuple.Create (tasks, cancellationToken));
394 var cont = t.ContinueWith (TaskActionInvoker.Create (continuationAction, tasks), cancellationToken, continuationOptions, scheduler);
401 public Task ContinueWhenAll<TAntecedentResult> (Task<TAntecedentResult>[] tasks,
402 Action<Task<TAntecedentResult>[]> continuationAction)
404 return ContinueWhenAll (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
407 public Task ContinueWhenAll<TAntecedentResult> (Task<TAntecedentResult>[] tasks,
408 Action<Task<TAntecedentResult>[]> continuationAction, CancellationToken cancellationToken)
410 return ContinueWhenAll (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
413 public Task ContinueWhenAll<TAntecedentResult> (Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>[]> continuationAction,
414 TaskContinuationOptions continuationOptions)
416 return ContinueWhenAll (tasks, continuationAction, cancellationToken, continuationOptions, GetScheduler ());
419 public Task ContinueWhenAll<TAntecedentResult> (Task<TAntecedentResult>[] tasks,
420 Action<Task<TAntecedentResult>[]> continuationAction,
421 CancellationToken cancellationToken, TaskContinuationOptions continuationOptions,
422 TaskScheduler scheduler)
424 return ContinueWhenAll ((Task[]) tasks, (o) => continuationAction (tasks), cancellationToken,
425 continuationOptions, scheduler);
428 public Task<TResult> ContinueWhenAll<TResult> (Task[] tasks, Func<Task[], TResult> continuationFunction)
430 return ContinueWhenAll<TResult> (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
433 public Task<TResult> ContinueWhenAll<TResult> (Task[] tasks, Func<Task[], TResult> continuationFunction,
434 TaskContinuationOptions continuationOptions)
436 return ContinueWhenAll<TResult> (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
439 public Task<TResult> ContinueWhenAll<TResult> (Task[] tasks, Func<Task[], TResult> continuationFunction,
440 CancellationToken cancellationToken)
442 return ContinueWhenAll<TResult> (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
445 public Task<TResult> ContinueWhenAll<TResult> (Task[] tasks, Func<Task[], TResult> continuationFunction,
446 CancellationToken cancellationToken,
447 TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
449 var t = new Task (l => {
450 var data = (Tuple<Task[], CancellationToken>) l;
451 Task.WaitAll (data.Item1, data.Item2);
452 }, Tuple.Create (tasks, cancellationToken));
454 var cont = t.ContinueWith<TResult> (TaskActionInvoker.Create (continuationFunction, tasks), cancellationToken, continuationOptions, scheduler);
461 public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
462 Func<Task<TAntecedentResult>[], TResult> continuationFunction)
464 return ContinueWhenAll<TAntecedentResult, TResult> (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
467 public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
468 Func<Task<TAntecedentResult>[], TResult> continuationFunction,
469 TaskContinuationOptions continuationOptions)
471 return ContinueWhenAll<TAntecedentResult, TResult> (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
474 public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
475 Func<Task<TAntecedentResult>[], TResult> continuationFunction,
476 CancellationToken cancellationToken)
478 return ContinueWhenAll<TAntecedentResult, TResult> (tasks, continuationFunction, cancellationToken, continuationOptions, GetScheduler ());
481 public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult> (Task<TAntecedentResult>[] tasks,
482 Func<Task<TAntecedentResult>[], TResult> continuationFunction,
483 CancellationToken cancellationToken,
484 TaskContinuationOptions continuationOptions,
485 TaskScheduler scheduler)
487 return ContinueWhenAll<TResult> ((Task[]) tasks,
488 (o) => continuationFunction (tasks),
490 continuationOptions, scheduler);
495 #region FromAsync IAsyncResult
497 public Task FromAsync (IAsyncResult asyncResult, Action<IAsyncResult> endMethod)
499 return FromAsync (asyncResult, endMethod, creationOptions);
502 public Task FromAsync (IAsyncResult asyncResult, Action<IAsyncResult> endMethod, TaskCreationOptions creationOptions)
504 return FromAsync (asyncResult, endMethod, creationOptions, GetScheduler ());
507 public Task FromAsync (IAsyncResult asyncResult, Action<IAsyncResult> endMethod, TaskCreationOptions creationOptions, TaskScheduler scheduler)
509 if (endMethod == null)
510 throw new ArgumentNullException ("endMethod");
512 return TaskFactory<object>.FromIAsyncResult (asyncResult,
514 endMethod (asyncResult);
516 }, creationOptions, scheduler);
519 public Task<TResult> FromAsync<TResult> (IAsyncResult asyncResult, Func<IAsyncResult, TResult> endMethod)
521 return FromAsync<TResult> (asyncResult, endMethod, creationOptions);
524 public Task<TResult> FromAsync<TResult> (IAsyncResult asyncResult, Func<IAsyncResult, TResult> endMethod, TaskCreationOptions creationOptions)
526 return FromAsync<TResult> (asyncResult, endMethod, creationOptions, GetScheduler ());
529 public Task<TResult> FromAsync<TResult> (IAsyncResult asyncResult, Func<IAsyncResult, TResult> endMethod, TaskCreationOptions creationOptions, TaskScheduler scheduler)
531 return TaskFactory<TResult>.FromIAsyncResult (asyncResult, endMethod, creationOptions, scheduler);
536 #region FromAsync Begin/End Method
538 public Task FromAsync (Func<AsyncCallback, object, IAsyncResult> beginMethod, Action<IAsyncResult> endMethod, object state)
540 return FromAsync (beginMethod, endMethod, state, creationOptions);
543 public Task FromAsync (Func<AsyncCallback, object, IAsyncResult> beginMethod, Action<IAsyncResult> endMethod,
544 object state, TaskCreationOptions creationOptions)
546 return TaskFactory<object>.FromAsyncBeginEnd (beginMethod,
547 l => { endMethod (l); return null; },
548 state, creationOptions);
551 public Task FromAsync<TArg1> (Func<TArg1, AsyncCallback, object, IAsyncResult> beginMethod, Action<IAsyncResult> endMethod,
552 TArg1 arg1, object state)
554 return FromAsync (beginMethod, endMethod, arg1, state, creationOptions);
557 public Task FromAsync<TArg1> (Func<TArg1, AsyncCallback, object, IAsyncResult> beginMethod, Action<IAsyncResult> endMethod,
558 TArg1 arg1, object state, TaskCreationOptions creationOptions)
560 if (endMethod == null)
561 throw new ArgumentNullException ("endMethod");
563 return TaskFactory<object>.FromAsyncBeginEnd (beginMethod,
564 l => { endMethod (l); return null; },
565 arg1, state, creationOptions);
568 public Task FromAsync<TArg1, TArg2> (Func<TArg1, TArg2, AsyncCallback, object, IAsyncResult> beginMethod,
569 Action<IAsyncResult> endMethod,
570 TArg1 arg1, TArg2 arg2, object state)
572 return FromAsync (beginMethod, endMethod, arg1, arg2, state, creationOptions);
575 public Task FromAsync<TArg1, TArg2> (Func<TArg1, TArg2, AsyncCallback, object, IAsyncResult> beginMethod,
576 Action<IAsyncResult> endMethod,
577 TArg1 arg1, TArg2 arg2, object state, TaskCreationOptions creationOptions)
579 if (endMethod == null)
580 throw new ArgumentNullException ("endMethod");
582 return TaskFactory<object>.FromAsyncBeginEnd (beginMethod,
583 l => { endMethod (l); return null; },
584 arg1, arg2, state, creationOptions);
587 public Task FromAsync<TArg1, TArg2, TArg3> (Func<TArg1, TArg2, TArg3, AsyncCallback, object, IAsyncResult> beginMethod, Action<IAsyncResult> endMethod,
588 TArg1 arg1, TArg2 arg2, TArg3 arg3, object state)
590 return FromAsync (beginMethod, endMethod, arg1, arg2, arg3, state, creationOptions);
593 public Task FromAsync<TArg1, TArg2, TArg3> (Func<TArg1, TArg2, TArg3, AsyncCallback, object, IAsyncResult> beginMethod, Action<IAsyncResult> endMethod,
594 TArg1 arg1, TArg2 arg2, TArg3 arg3, object state, TaskCreationOptions creationOptions)
596 if (endMethod == null)
597 throw new ArgumentNullException ("endMethod");
599 return TaskFactory<object>.FromAsyncBeginEnd (beginMethod,
600 l => { endMethod (l); return null; },
601 arg1, arg2, arg3, state, creationOptions);
604 public Task<TResult> FromAsync<TResult> (Func<AsyncCallback, object, IAsyncResult> beginMethod, Func<IAsyncResult, TResult> endMethod,
607 return FromAsync (beginMethod, endMethod, state, creationOptions);
610 public Task<TResult> FromAsync<TResult> (Func<AsyncCallback, object, IAsyncResult> beginMethod, Func<IAsyncResult, TResult> endMethod,
611 object state, TaskCreationOptions creationOptions)
613 return TaskFactory<TResult>.FromAsyncBeginEnd (beginMethod, endMethod, state, creationOptions);
616 public Task<TResult> FromAsync<TArg1, TResult> (Func<TArg1, AsyncCallback, object, IAsyncResult> beginMethod, Func<IAsyncResult, TResult> endMethod,
617 TArg1 arg1, object state)
619 return FromAsync (beginMethod, endMethod, arg1, state, creationOptions);
622 public Task<TResult> FromAsync<TArg1, TResult> (Func<TArg1, AsyncCallback, object, IAsyncResult> beginMethod, Func<IAsyncResult, TResult> endMethod,
623 TArg1 arg1, object state, TaskCreationOptions creationOptions)
625 return TaskFactory<TResult>.FromAsyncBeginEnd (beginMethod, endMethod, arg1, state, creationOptions);
628 public Task<TResult> FromAsync<TArg1, TArg2, TResult> (Func<TArg1, TArg2, AsyncCallback, object, IAsyncResult> beginMethod,
629 Func<IAsyncResult, TResult> endMethod,
630 TArg1 arg1, TArg2 arg2, object state)
632 return FromAsync (beginMethod, endMethod, arg1, arg2, state, creationOptions);
635 public Task<TResult> FromAsync<TArg1, TArg2, TResult> (Func<TArg1, TArg2, AsyncCallback, object, IAsyncResult> beginMethod, Func<IAsyncResult, TResult> endMethod,
636 TArg1 arg1, TArg2 arg2, object state, TaskCreationOptions creationOptions)
638 return TaskFactory<TResult>.FromAsyncBeginEnd (beginMethod, endMethod, arg1, arg2, state, creationOptions);
641 public Task<TResult> FromAsync<TArg1, TArg2, TArg3, TResult> (Func<TArg1, TArg2, TArg3, AsyncCallback, object, IAsyncResult> beginMethod, Func<IAsyncResult, TResult> endMethod,
642 TArg1 arg1, TArg2 arg2, TArg3 arg3, object state)
644 return FromAsync (beginMethod, endMethod, arg1, arg2, arg3, state, creationOptions);
647 public Task<TResult> FromAsync<TArg1, TArg2, TArg3, TResult> (Func<TArg1, TArg2, TArg3, AsyncCallback, object, IAsyncResult> beginMethod, Func<IAsyncResult, TResult> endMethod,
648 TArg1 arg1, TArg2 arg2, TArg3 arg3, object state, TaskCreationOptions creationOptions)
650 return TaskFactory<TResult>.FromAsyncBeginEnd (beginMethod, endMethod, arg1, arg2, arg3, state, creationOptions);
655 TaskScheduler GetScheduler ()
657 return scheduler ?? TaskScheduler.Current;