问题
I was wondering if it is possible to increase buffer size on WebClient Async data upload, because currently it pushes ~320kB/s maximum.
My current code:
using (WebClient Client = new WebClient())
{
byte[] Buffer = File.ReadAllBytes(this.WorkItem.FileLocation);
Client.UploadProgressChanged += new UploadProgressChangedEventHandler(Client_UploadProgressChanged);
Client.UploadDataCompleted += new UploadDataCompletedEventHandler(Client_UploadDataCompleted);
Client.UploadDataAsync(new Uri("-snip-"), Buffer);
}
Edit
Connection is not the limiting factor. ( its 300mbit connection, web-servers push content at ~30-40mB/s mark )
回答1:
If you want more control over how the data is buffered you need to use the HttpWebRequest
class. With this class you can choose your read buffer reading from a FileStream
and then how much you are writing to the network stream. Doing 4MB reads and 32KB writes was optimal for maxing out my network throughput (although you will have to do your own benchmarks to see which buffers work best in your scenario).
来源:https://stackoverflow.com/questions/11719804/c-sharp-webclient-upload-speeds