Part 33 :- Thread Vs Task in C# | Multithreading/asynchronous and Parallel Programming in C#

preview_player
Показать описание
•Both the Thread class and the Task class are used for parallel programming in C#.

• A Thread is a lower-level implementation while a Task is a higher-level implementation.

• Thread class takes resources while a Task does not.

•Thread class also provides more control than the Task class.

•A Thread should be preferred for any long-running operations, while a Task should be preferred for any other asynchronous operations.

•The task can return a result. There is no direct mechanism to return the result from a thread.

•Task supports cancellation through the use of cancellation tokens. But Thread doesn’t.

•A task can have multiple processes happening at the same time. Threads can only have one task running at a time.

•We can easily implement Asynchronous using ’async’ and ‘await’ keywords.

•A new Thread()is not dealing with Thread pool thread, whereas Task does use thread pool thread.

Support Us

#csharp #multithread #csharpprogramming
Рекомендации по теме