See Also: Task<TResult> Members
- Documentation for this section has not yet been entered.
System.Threading.Tasks.Task`1 instances may be created in a variety of ways. The most common approach is by using the task's Task`1.Factory property to retrieve a System.Threading.Tasks.TaskFactory`1 instance that can be used to create tasks for several purposes. For example, to create a System.Threading.Tasks.Task`1 that runs a function, the factory's TaskFactory.StartNew(Action, System.Threading.CancellationToken) method may be used:
// C# var t = Task<int>.Factory.StartNew(() => GenerateResult()); ' Visual Basic Dim t = Task(Of Integer).Factory.StartNew(Function() GenerateResult())
For more complete examples, see Task Parallelism (Task Parallel Library).
The System.Threading.Tasks.Task`1 class also provides constructors that initialize the task but that do not schedule it for execution. For performance reasons, the StartNew method should be the preferred mechanism for creating and scheduling computational tasks, but for scenarios where creation and scheduling must be separated, the constructors may be used, and the task's Task.Start method may then be used to schedule the task for execution at a later time.