Tasks vs Themes in .NET 4.5

Well in .Net 4, there is a new Tasks function, and I was wondering if I can rely on it alog using Async/Awaitin .Net 4.5for all methods that I want to execute asynchronously, or in some situations I will have to use a separate one Thread, especially that I read that Task.Run uses ThreadPoolto execute the asynchronous method.

Conclusion: Does using a combination Async/Awaitwith Taskscan free me from using Threads?

+5
source share
1 answer

If you specify an option TaskCreationOptions.LongRunning(there is also an equivalent for continuations), then the task will not use the thread pool thread, it will use the regular one Thread. Technically, this is an implementation detail and is not part of the specifications, but it is not a completely unfounded assumption that you can rely on.

Given that you can do something using Taskwhat you can do with Threaddirectly.

, , - Thread , , , TPL. -, Thread, () Tasks.

, , .NET 4.0, Task.

+5

All Articles