S
S
skvoshiz2014-12-22 22:40:53
Programming
skvoshiz, 2014-12-22 22:40:53

Task or Thread in C# .NET 4.0 WPF?

Hello, I am writing a program in C# platform exactly .NET 4.0, which is better to use, Task or Thread? Because it is more convenient to use Task on .NET 4.5!
What are their main differences?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Elizariev, 2014-12-23
@skvoshiz

Thread (thread, thread) - is an encapsulation of a processor thread. This is a software wrapper over the functionality of your system. Task (task) - represents a unit of work that can be performed in parallel. The use of one or another tool depends on your tasks. For example, if you need to perform operations in the background, your choice is a thread. If you need to perform calculations in parallel or wait for an asynchronous operation (for example, I / O), then your choice is a task.

C
Cyril, 2014-12-23
@teoadal

EMNP, the main differences are: Task is taken from the thread pool (therefore, there is practically no overhead for creating), and Thread - the thread is created by itself (with overhead, but more freedom, for example, to give a name). The pool is limited in number (new ones will be queued), Thread can be created as you like and whenever you want, but if the critical mass is exceeded, they will cause more braking than acceleration.
.NET 4.5 introduced async/await, a syntactic sugar that makes code more beautiful and understandable. .NET 4 for the same purposes, you can use this: blogs.msdn.com/b/bclteam/archive/2012/10/22/using-...

H
haiku, 2014-12-23
@haiku

If you do not need any ingenious optimizations, feel free to choose Task. Threads for "handmade". If you do not want a hell of a headache from scratch, manual picking in threads is completely useless to you. Tasks give async and simplicity.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question