Monday, April 16, 2012

Best way to wait async to complete on WP7

i having some hard time on this, i'm trying to get my first WP7 app out.
I have an method that download the html from a website and regex it, but the problem is, when i click the button for the first time, nothing happens, on the second try, it fills the grid perfectly, when i was debugging i saw the string with the HTML is already assigned correctly before the method even starts. So, the question is, what is the simplest way to wait for async method to finish?
I've searched about CTP async and some other ways, but i can't manage to make it work.
Here's is the code



   public static void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
doc = e.Result;
}

public static List<Row> Search(string number)
{
WebClient wClient = new WebClient();

sNumber = number;
int i = 0;
DateTime datetime;

wClient.DownloadStringAsync(new Uri(sURL + sNumber));
wClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
/*More code*/
}


The button calls the method Search() and uses the list returned to fill the grid.





No comments:

Post a Comment