Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pause/Resume Upload in C#

I'm looking for a way to pause or resume an upload process via C#'s WebClient.

pseudocode:

WebClient Client = new WebClient();
Client.UploadFileAsync(new Uri("http://mysite.com/receiver.php"), "POST", "C:\MyFile.jpg");

Maybe something like..

Client.Pause();

any idea?


2 Answers

WebClient doesn't have this kind of functionality - even the slightly-lower-level HttpWebRequest doesn't, as far as I'm aware. You'll need to use an HTTP library which gives you more control over exactly when things happen (which will no doubt involve more code as well, of course). The point of WebClient is to provide a very simple API to use in very simple situations.

like image 55
Jon Skeet Avatar answered Aug 10 '26 14:08

Jon Skeet


As stated by Jon Skeet, this is not available in the Webclient not HttpWebRequest classes.

However, if you have control of the server, that receives the upload; perhaps you could upload small chunks of the file using WebClient, and have the server assemble the chunks when all has been received. Then it would be somewhat easier for you to make a Pause/resume functionality.

If you do not have control of the server, you will need to use an API that gives you mere control, and subsequently gives you more stuff to worry about. And even then, the server might give you a time-out if you pause for too long.

like image 25
driis Avatar answered Aug 10 '26 15:08

driis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!