Note that there are some explanatory texts on larger screens.

plurals
  1. POBandwidth throttling in C# windows application
    text
    copied!<p>I need to implement Bandwidth Throttling feature in windows application. There are two threads on SO:</p> <ul> <li><a href="https://stackoverflow.com/questions/847422/how-to-programatically-limit-bandwidth-usage-of-my-c-sharp-windows-forms-applica">How to programatically limit bandwidth usage of my c# windows forms application</a></li> <li><a href="https://stackoverflow.com/questions/371032/bandwidth-throttling-in-c-sharp">Bandwidth throttling in C#</a></li> </ul> <p>But that is for web app. I need it for windows app. How can I implement it in windows? Can I use above mentioned links for windows applications?</p> <p>Here is the code I am using:</p> <pre class="lang-cs prettyprint-override"><code>// Apply bandwidth control int uploadLimit = GlobalClass.GetFileUploadLimit(); if (uploadLimit &gt; 0) { long bps = uploadLimit * 1024; const int BufferSize = 8192; MemoryStream mstream = new MemoryStream();//Stream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, BufferSize); // Openup source stream. using (FileStream sourceStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, BufferSize)) { // Create throttled destination stream. ThrottledStream destinationStream = new ThrottledStream(mstream, bps); byte[] buffer = new byte[BufferSize]; int readCount = sourceStream.Read(buffer, 0, BufferSize); while (readCount &gt; 0) { destinationStream.Write(buffer, 0, readCount); readCount = sourceStream.Read(buffer, 0, BufferSize); client.FileUpload(Convert.ToInt16(userId), System.IO.Path.GetFileName(fileName), buffer); //Webservice: Here is the problem } } } </code></pre> <p>In the above code, there is a web service I am using to upload file. This web service takes whole file in bytes at once. So in this case, I cannot upload file in chunks. Can anyone suggest me the some way to accomplish this or Shall I do change in service to accept data in chunks?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload