Question

I have an application that upload a file to S3 Amazon which internally uses ThrottledStream class to control the bandwidth. I want to give the user the provision to adjust bandwidth as per the percentage between 0-100%, as client will not understand byte transfer rate. Throlled stream takes input parameter as FileStream/Stream and bps (byte/bit per second). How can i adjust the bps value based on the percentage set by user? I have limited knowledge of throttling, your suggestions will really help me.

Was it helpful?

Solution

You're going to have to pick a maximum value, such as 100kbs then set the rate based on the percentage.

long bps = (long)(102400 * ((double)percent / 100.0);   
if (percent == 100)
   bps = ThrottledStream.Infinite;
ts = new ThrottledStream(originalDestinationStream, bps);

I haven't compiled it, but I would guess something like that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top