title: Bandwidth throttling in C#
body: <p>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.</p>
  
  <p>I have read up on the <a href="http://en.wikipedia.org/wiki/Token_bucket" rel="noreferrer">token bucket</a> and <a href="http://en.wikipedia.org/wiki/Leaky_bucket" rel="noreferrer">leaky bucket</a> 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.</p>
  
  <p>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.</p>
  
  <p>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?</p>
  
  <p>EDIT: I am interested in throttling both incoming and outgoing data, where I have no control over the opposite end of the stream.</p>