Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Task::Start Method ()

 

Starts the Task, scheduling it for execution to the current TaskScheduler.

Namespace:   System.Threading.Tasks
Assembly:  mscorlib (in mscorlib.dll)

public:
void Start()

Exception Condition
ObjectDisposedException

The Task instance has been disposed.

InvalidOperationException

The Task is not in a valid state to be started. It may have already been started, executed, or canceled, or it may have been created in a manner that doesn't support direct scheduling.

A task may be started and run only once. Any attempts to schedule a task a second time will result in an exception.

The Start is used to execute a task that has been created by calling one of the Task constructors. Typically, you do this when you need to separate the task's creation from its execution, such as when you conditionally execute tasks that you've created. For the more common case in which you don't need to separate task instantiation from execution, we recommend that you call an overload of the Task::Run or TaskFactory::StartNew method.

For information on handling exceptions thrown by task operations, see Exception Handling (Task Parallel Library).

The following example calls the Task(Action^) constructor to instantiate a new Task object that displays its task ID and managed thread ID and then executes a loop. It then calls the Start method to execute the task. Since this is a console app, the call to the Wait method is necessary to prevent the app from terminating before the task finishes execution.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 5.0
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2017 Microsoft