WebClient Progress Percentage AsyncUpload always returns 50%

I use Webclient to upload data using an Async call to the server,

    WebClient webClient = new WebClient();
   webClient.UploadDataAsync(uri , "PUT", buffer, userToken);

I have connected DatauploadProgress and DatauploadCompleted Events to the corresponding callback functions

        // Upload Date Progress
        webClient.UploadProgressChanged += new 
        UploadProgressChangedEventHandler(UploadProgressCallback);

      // Upload Date Progress
     void UploadProgressCallback(object sender, UploadProgressChangedEventArgs e)
    {
        // Magic goes here 
     logger.writeToLog("Percentage =" + e.ProgressPercentage);
    }

e.ProgressPercentagealways returns 50.. no matter what the size of the downloaded file was (tried different sizes from 10 kb to 60 mb). the function itself is called only twice (very quickly), and the percentage shows 50! .. which is illogical especially with large files ...

e.BytesSentdoesn't help ... always shows the file size in bytes: S (for example: if the file size was 63,000, I would get e.BytesSent = 63,000ande.ProgressPercentage= 50

Can someone point out a problem?

+5
1

, UploadFileAsync UploadData.

UploadDataAsync ( , , , MSDN).

, UploadFileAsync, UploadProgressChanged. args BytesSent TotalBytesToSend, .

, , , , (.NET ), , - , , UploadProgressChanged UploadDataAsync - , , .

, UploadFileAsync , .

+7

All Articles