tags:

views:

144

answers:

1

Hello,

VS 2008 SP1

I am using the DownloadStringAysnc. But the ProgressChanged event doesn't show progress until after the string has been downloaded.

Even when I try and download a string which is contained in a big file. The programs remains response so I know it is doing something. However, it is when the progress has completed that the progressChanged event fires.

I known this as the progressChanged and the DownloadStringCompleted fire immediately after each other. However, they should be a pause as the file is quite big.

This is the code snippet I am currently using. And the output below. What is strange the e.progresspercentage is 100%. And seems to get called twice.

Many thanks for any advise,

Output in the progress changed event
Progress changed Version userstate: [ Version1 ]
progressBar1.Value [ 100 ]
Progress changed Version userstate: [ Version1 ]
progressBar1.Value [ 100 ]
Completed Version userstate: [ Version1 ]


private void UpdateAvailable()
        {
            WebClient wbCheckUpdates = new WebClient();
            wbCheckUpdates.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wbCheckUpdates_DownloadProgressChanged);
            wbCheckUpdates.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wbCheckUpdates_DownloadStringCompleted);
            DownloadFiles df = new DownloadFiles();
            string webServerURL = df.webServerPath;

            wbCheckUpdates.DownloadStringAsync(new Uri(Path.Combine(webServerURL, "version.txt")), "Version1"); 
        }




void wbCheckUpdates_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            Console.WriteLine("Progress version changed userstate: [ " + e.UserState + " ]");
            progressBar1.Value = e.ProgressPercentage;
            Console.WriteLine("progressBar1.Value [ " + this.progressBar1.Value + " ]");
        }

void wbCheckUpdates_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            Console.WriteLine("Completed version userstate: [ " + e.UserState + " ]");
        }

=========== Edited using DownloadDataAysnc ===============

wbCheckUpdates.DownloadDataAsync(new Uri(Path.Combine(webServerURL, "version.txt")), "Version1");


void wbCheckUpdates_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            byte[] result = e.Result;           
            Console.WriteLine("Completed data: [ " + System.Text.ASCIIEncoding.Default.GetString(result) + " ]");
        }

The results are the same:

Progress changed Version userstate: [ Version1 ]
progressBar1.Value [ 100 ]
Progress changed Version userstate: [ Version1 ]
progressBar1.Value [ 100 ]
Completed data: [ 1.0.11 ]
+2  A: 

According to the documentation, DownloadStringAsync does not report progress. See the documentation of the WebClient.DownloadProgressChanged Event.

John Saunders
Hello, I have just edited my source code in my question. Now I am using the DownloadDataAysnc. As according to that website that should show progress. However, the result are the same. Thanks.
robUK