C# - 线程池VS任务 [英] C# - ThreadPool vs Tasks

查看:171
本文介绍了C# - 线程池VS任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于有些人可能会在.NET 4.0中所看到的,他们已经增加了一个新的命名空间 System.Threading.Tasks 这基本上是什么手段,一个任务。我只是一直在使用它了几天,使用线程池。

As some may have seen in .NET 4.0, they've added a new namespace System.Threading.Tasks which basically is what is means, a task. I've only been using it for a few days, from using ThreadPool.

哪一个更有效和更消耗资源? (或者只是更好的整体?)

Which one is more efficient and less resource consuming? (Or just better overall?)

推荐答案

任务命名空间的目的是提供一个可插拔的体系结构,使多任务的应用程序更容易编写,更灵活。

The objective of the Tasks namespace is to provide a pluggable architecture to make multi-tasking applications easier to write and more flexible.

该实现使用的TaskScheduler 对象来控制任务的处理。这有,你可以重写以创建自己的任务处理虚拟方法。方法包括例如

The implementation uses a TaskScheduler object to control the handling of tasks. This has virtual methods that you can override to create your own task handling. Methods include for instance

protected virtual void QueueTask(Task task)
public virtual int MaximumConcurrencyLevel

将有一个小的开销,以使用默认的实现作为有围绕.NET线程实现一个包装,但我不希望它是巨大的。

There will be a tiny overhead to using the default implementation as there's a wrapper around the .NET threads implementation, but I'd not expect it to be huge.

有一个(草案)实现了在单个线程的这里

There is a (draft) implementation of a custom TaskScheduler that implements multiple tasks on a single thread here.

这篇关于C# - 线程池VS任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆