Home >Backend Development >C++ >Task.Run() or Task.Factory.StartNew(): When Should I Use Which?
Comparison of Task.Run() and Task.Factory.StartNew()
Want to execute a method in a new task? There are two options: Task.Run() and Task.Factory.StartNew(). But what is the difference between the two methods?
While both use the thread pool and start the specified method immediately, they differ in their custom functionality.
Task.Run()
Task.Run() appeared in .NET 4.5 and is a simple and efficient way to start a task. Its limited parameters make it a suitable choice for basic scenarios.
Task.Factory.StartNew()
Task.Factory.StartNew() is available in older .NET versions and provides greater flexibility and control. It allows you to:
When should each method be used?
The above is the detailed content of Task.Run() or Task.Factory.StartNew(): When Should I Use Which?. For more information, please follow other related articles on the PHP Chinese website!