I am trying to track the progress of a file upload, but continue to end up from a dead point (loading from a C # application, not a web page).
I tried using WebClient as such:
class Program { static volatile bool busy = true; static void Main(string[] args) { WebClient client = new WebClient();
The file is downloaded and the progress is printed, but the progress is much faster than the actual download, and when downloading a large file, progress will peak in a few seconds, but the actual download takes several minutes (this is not just waiting for a response, all the data has not yet reached the server).
So I tried to use HttpWebRequest for streaming data (I know that this is not the exact equivalent of loading a file, since it does not create multipart/form-data content, but it serves to illustrate my problem). I set AllowWriteStreamBuffering = false and set ContentLength as suggested by this question / answer :
class Program { static void Main(string[] args) { FileInfo fileInfo = new FileInfo(args[0]); HttpWebRequest client = (HttpWebRequest)WebRequest.Create(new Uri("http://uploadUri/"));
The request does not start until the entire file is written to the stream and already shows full progress at the time of its launch (I use fiddler to check this). I also tried setting SendChunked to true (with and without ContentLength setting). It seems that the data is still cached before being sent over the network.
Is there something wrong with one of these approaches, or maybe there is another way to track the progress of downloading files from a Windows application?
source share