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.

TaskFactory::StartNew Method (Action^)

 

Creates and starts a task.

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

public:
Task^ StartNew(
	Action^ action
)

Parameters

action
Type: System::Action^

The action delegate to execute asynchronously.

Return Value

Type: System.Threading.Tasks::Task^

The started task.

Exception Condition
ArgumentNullException

The action argument is null.

Calling StartNew is functionally equivalent to creating a task by using one of its constructors, and then calling the Task::Start method to schedule the task for execution.

Starting with the .NET Framework 4.5, you can use the Task::Run(Action^) method as a quick way to call StartNew(Action^) with default parameters. Note, however, that there is a difference in behavior between the two methods regarding : Task::Run(Action^) by default does not allow child tasks started with the TaskCreationOptions::AttachedToParent option to attach to the current Task instance, whereas StartNew(Action^) does. For more information and code examples, see Task.Run vs Task.Factory.StartNew in the Parallel Programming with .NET blog.

The following example uses the StartNew(Action^) method to repeatedly invoke an Action delegate that generates a random number, interprets it as a Unicode code point, converts it to a UTF16-encoded code unit, and displays information about the resulting character or characters.

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