开发者

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 f开发者_开发百科or 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜