title: Bandwidth throttling while copying files between computers
body: <p>I've been trying to make a program to transfer a file with bandwidth throttling (after zipping it) to another computer on the same network. </p>
  
  <p>I need to get its bandwidth throttled in order to avoid saturation (Kind of the way Robocopy does).</p>
  
  <p>Recently, I found the <code>ThrottledStream</code> class, but It doesn't seem to be working, since I can send a 9MB with a limitation of 1 byte throttling and it still arrives almost instantly, so I need to know if there's some misapplication of the class.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>using (FileStream originStream = inFile.OpenRead())    
  using (MemoryStream compressedFile = new MemoryStream())      
  using (GZipStream zippingStream = new GZipStream(compressedFile, CompressionMode.Compress))
  {
      originStream.CopyTo(zippingStream); 
      using (FileStream finalDestination = File.Create(destination.FullName + "\\" + inFile.Name + ".gz"))
      {
          ThrottledStream destinationStream = new ThrottledStream(finalDestination, bpsLimit);
          byte[] buffer = new byte[bufferSize];
          int readCount = compressedFile.Read(buffer,0,bufferSize);
          while(readCount &gt; 0)
          {
              destinationStream.Write(buffer, 0, bufferSize);
              readCount = compressedFile.Read(buffer, 0, bufferSize);
          }
      }
  }
  </code></pre>
  
  <p>Any help would be appreciated.</p>