Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7800477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:39:04+00:00 2026-06-02T00:39:04+00:00

i having some hard time on this, i’m trying to get my first WP7

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:39:06+00:00Added an answer on June 2, 2026 at 12:39 am

    The wClient.DownloadStringAsync(new Uri(sURL + sNumber)); method executes after all the code in that method is executed.

    1) At first doc is null

    2) Then you call wClient.DownloadStringAsync(new Uri(sURL + sNumber)); but doesn’t execute!!

    3) Then you return doc (which is still null)

    4) After all this, wClient.DownloadStringAsync(new Uri(sURL + sNumber)); is executed and doc is filled.

    That is why when you press the Search button for the 2nd time, the grid is filled perfectly

    N.B. You must register the DownloadStringCompletedEventHandler before calling the async method. And you only have to register this event handler once, i.e. in the constructor, because you are adding an event handler everytime this method is executed. So if you press the Search button for 5 times, the grid is filled for 5 times although you don’t notice

    One solution would be:

    Here’s is the code

       public static void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Result != null)
            {
                //populate grid view
            }
        }
    
        public static void Search(string number)
        {
            WebClient wClient = new WebClient();
    
            sNumber = number;
            int i = 0;
            DateTime datetime;
    
            wClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted); //this should be added in the constructor, so it would only be added once
            wClient.DownloadStringAsync(new Uri(sURL + sNumber));
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a hard time finding this out from the documentation. I have some
I'm having some hard time figuring out what's wrong in this simple code: This
I'm having some hard time trying to send an email from my app. I
Ok, I have been having a VERY hard time figuring this out. I guess
For some reason, I'm having a hard time trying to cover the block of
I'm having a hard time wrapping my head around this and need some help
I'm having a hard time understanding this regex stuff... I have a string like
I'm having some hard time running my app on Heroku - The app runs
So, I am having a hard time getting this to work. I am trying
I'm doing some homework, and having a hard time understanding closures. This is in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.