System.Threading.Task
Added in .NET 4.0
A Task represents an asynchronous operation.
What is the Task Parallel Library ?
This replaces the earlier Processor and Thread classes with a new class called Task.
The System.Threading.Tasks namespace has been designed for executing multi-threaded applications on machines that have multiple core processors.
The new Task class has a higher level of abstraction than the Thread.
Asynchronous implementation is easy in a task, using' async' and 'await' keywords.
A task can return a result
A task can have multiple processes happening at the same time.
A task can have multiple processes happening at the same time.
A task can support cancellation through the use of cancellation tokens
link - learn.microsoft.com/en-us/dotnet/standard/parallel-programming/
link - learn.microsoft.com/en-us/dotnet/standard/parallel-programming/task-parallel-library-tpl
These are much more powerful than the Backgroundworker
partitioning of the work,
taking care of state management,
scheduling threads on the thread pool,
using callback methods
enabling continuation or cancellation of tasks.
Data and task parallelism
Schedule threads in a thread pool
Ability to use all available cores
Cancellation of work
Partitioning of work
A task is a lightweight object that manages a parallelism unit of work
Tasks use the CLRs thread pool which avoids creating a new thread.
Methods
Task.Run - Queues the specified work to run on the ThreadPool and returns a task or Task<TResult> handle for that work.
Task.RunSynchronously - Runs the Task synchronously on the current TaskScheduler.
Task.Start - Starts the Task.
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext