简体   繁体   中英

WebClient & DownloadString, make sure string is fully downloaded to display in TextBlock.Text

I'm having a problem with WebClient. I have a TextBox (used for URL), then a submit button which calls TextBox.Text and then does the WebClient stuff. Then I want to display the HTML in TextBlock.text but it doesn't show unless I quick twice or more.

        WebClient search_client = new WebClient();
        search_client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(search_client_DownloadStringCompleted);
        search_client.DownloadStringAsync(new System.Uri(URL));

Then for the DownloadStringCompletedEventHandler, I have if e.Error == null then do this.html = e.Result . Where html is declared globally in the class.

I want to make sure that WebClient is finished downloading so it can display it in the TextBlock.

When DownloadStringCompleted is triggered, the download already completed, so you have nothing to worry about in terms of expecting the download to complete.

If you organized everything correctly, you only need to click once and wait. The async call will return the result when it completes (which might take a while depending on the internet connection).

Is your HTML-displaying TextBox bound to the html property or you are displaying data in some other manner?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM