开发者

xna download website source code

开发者 https://www.devze.com 2023-02-03 19:49 出处:网络
I have to download the html code of a web site during the game. I am taking the poster url of a movie from the imdb web site by scrapping the html ( also other informations ). I have to do the downloa

I have to download the html code of a web site during the game. I am taking the poster url of a movie from the imdb web site by scrapping the html ( also other informations ). I have to do the download process many times during the game for different movies. I can download and scrap the html but downloading the html takes too m开发者_如何学编程uch time and it causes the game to slow down(freeze while downloading). How can I solve this problem? My one approach is to download and scrap all the information and store them in a database before the game and during the game access this information from the database. I think this will work properly but that is not what I exactly want. It would be better if it is dynamic. I also thought of using multi-threading but I am a bit confused about how to implement threading in xna. I read some articles about it but it is not so clear. I mean when should I start the thread and what about the update function etc. I need your help guys

Thanks..


Check out this nice little helper class I wrote, sounds like it will take care of your problem:
http://codecube.net/2010/09/windows-phone-7-webhelper/

The basic idea is that you can use a very simplified API, and the class will download the HTML on async and execute your delegate when it gets the results:

string u = @"http://bing.com";
WebHelper.Get(u, html =>
    {
        Debug.WriteLine(html);
    });

Of course, I wrote that class with the windows phone in mind ... but if I'm not mistaken it should work on windows/xna4 no problem as well.


This has nothing to do with XNA. To solve the freeze in your main thread, you should move the downloading on another thread. Btw, how do you download the file? You can use the WebClient.DownloadFileAsync which downloads a file asynchronously.

0

精彩评论

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