在C#中的带宽限制 [英] Bandwidth throttling in C#

查看:727
本文介绍了在C#中的带宽限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个程序,连续发送的背景数据流,我想允许用户设置为上传和下载限制的上限。

I am developing a program that continually sends a stream of data in the background and I want to allow the user to set a cap for both upload and download limit.

我已经在令牌桶并的漏桶 alghorhithms,貌似后者似乎适合的描述,因为这不是最大化的网络带宽,而是被尽可能不引人注目的问题。

I have read up on the token bucket and leaky bucket alghorhithms, and seemingly the latter seems to fit the description since this is not a matter of maximizing the network bandwidth but rather being as unobtrusive as possible.

我在我将如何实现这却丝毫不能确定。一个自然的方法是扩展抽象Stream类,使之简单,扩展现有的流量,但这样做并不需要额外的线程的参与发送的数据,同时接收(漏桶)?做同样在其他实现任何提示将AP preciated。

I am however a bit unsure on how I would implement this. A natural approach is to extend the abstract Stream class to make it simple to extend existing traffic, but would this not require the involvement of extra threads to send the data while simultaneously receiving (leaky bucket)? Any hints on other implementations that do the same would be appreciated.

另外,虽然我可以修改程序多少数据接收,如何做带宽限制,工作在C#的水平?将在计算机仍收到的数据,仅仅保存,有效地消除节流作用还是会等到我要求得到更多?

Also, although I can modify how much data the program receives, how well does bandwidth throttling work at the C# level? Will the computer still receive the data and simply save it, effectively canceling the throttling effect or will it wait until I ask to receive more?

编辑:我感兴趣的是节流传入和传出的数据,在那里我有过流的另一端没有控制权

I am interested in throttling both incoming and outgoing data, where I have no control over the opposite end of the stream.

推荐答案

请参见这篇文章ThrottledStream类。它应该满足您的需求。

See this article about ThrottledStream class. It should fit your needs.

这篇关于在C#中的带宽限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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