Replies: 1 comment
-
Unfortunately if there is a bug with WebClient, it may not get fixed. The .NET team considers it a legacy API. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
To summarize the problem,
UploadProgressChanged
is called several times,BytesSent
goes up until it reached the file size but the file is not actually SENT during that time. The file is sent AFTER.Tried this with sendDataAsync, sendDataTaskAsync, and UploadFileTaskAsync, with the same result. When the code comes to
client.UploadFileTaskAsync
, UploadProgressChanged will start to be called repeatedly and I can see by theConsole.Writeline
that it counts up to the size of the file I'm trying to send very quickly. After this program will stand still for a minute and end. Looking at this with fiddler shows that the file is not actually sent until after the count up is done.I can see that the value of
e.TotalBytesToSend
is always -1. I looked this up in MSDN but can't find anything about the meaning of -1. I tried doing this call with curl and using that I can see in fiddler that the file is being uploaded when curl is counting up the bytes sent so apparently it is possible to get it right, I just don't see how.This is probably related to the similar issue I posted about yesterday when I tried to get progress using
httpwebrequest
https://stackoverflow.com/questions/65391831/showing-file-upload-progress-with-httpwebrequestHere is a minimal program that I can reproduce the issue with.
I did some .NET source stepping to find out more. Looking at the code for WebClient I find nothing changing the ProgressData.TotalBytesToSend from -1. Looking at the code around Line 1031 https://github.com/dotnet/runtime/blob/master/src/libraries/System.Net.WebClient/src/System/Net/WebClient.cs#L1031 we can see the code that updates BytesSent.
using (Stream writeStream = await request.GetRequestStreamAsync().ConfigureAwait(false)){
await writeStream.WriteAsync(new ReadOnlyMemory(header)).ConfigureAwait(false);
_progress.BytesSent += header.Length;
PostProgressChanged(asyncOp, _progress);}
Looking up stream used at https://github.com/dotnet/runtime/blob/master/src/libraries/System.Net.Requests/src/System/Net/RequestStream.cs#L18, it's just a memory stream. What is measured in my app is how much is written to memory.
Is there something I'm missing here? If there is no code changing TotalBytesToSend and the BytesSent is just how many bytes are written to a memory and not sent, it seems like this function is broken to me?
I zipped my application and posted it here in case someone want to try the same thing as I did. https://www.dropbox.com/s/kllcwd79738370a/filetransfertest.zip?dl=0
Beta Was this translation helpful? Give feedback.
All reactions