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 6944325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:17:33+00:00 2026-05-27T13:17:33+00:00

so I have a class request that has a method call that makes an

  • 0

so I have a class request that has a method call that makes an http request

in my main class, when the user presses a button, an isntance of the class req is made and the method call makes the http request is invoked.

I want to have a certain way to know when the call is done so that I can update my textblock with the results

I tried to put that in the button click event handler method:

        req.call(textBox1.Text);
        Dispatcher.BeginInvoke(() =>
        {
            //req is the class instance, outputMessage is the string holds 
            //the result of the http request
            //resultTextBlock is the one I wanna update with the result
            while (req.outputMessage == "none") ;
            resultTextBlock.Text = req.outputMessage;
        });

in the button click event handler, but then the app goes into infinite loop and never finishes, the http request takes fraction of a second to be made if that’s matter

I want to be able to update the resultTextBlock whenever the result is grabbed.

  • 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-05-27T13:17:34+00:00Added an answer on May 27, 2026 at 1:17 pm

    You want a callback from the request once it is completed. This is supported i.e. by the WebClient:

    using (WebClient wc = new WebClient())
    {
        wc.DownloadStringAsync(new Uri("http://stackoverflow.com"), null);
        wc.DownloadStringCompleted += (s, e) =>
        {
            string outputMessage = e.Result;
            Dispatcher.BeginInvoke(() =>
            {
                    resultTextBlock.Text = outputMessage;
    
            });
        };
    }
    

    Edit:

    You could pass in a delegate to your req class that you pass the result string (also note the naming guidelines, should be all Uppercase), so change the method signature as follows:

    public void Call(string url, Action<string> notifyCompletion)
    {
    
     //once completed:
      notifyCompletion(result);
    }
    

    And change the calling code to:

    Req myRequest = new Req();
    myRequest.Call(textBox1.Text, s => 
    {
       Dispatcher.BeginInvoke(() =>
       {
           resultTextBlock.Text = outputMessage;
       });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTTP Request Dispatcher class that works most of the time, but
I have a class that builds a request based on a few passed in
in AS3, I have an external class ImageLoader, that loads an image upon request.
I have class method that returns a list of employees that I can iterate
I have created an abstract base class Animal which has public virtual abstract method
I have a class that extends RemoteServiceServlet. This class has several methods, in one
I have a class which has a field the same name as a method
I have a class (let's call it MyService ) that accepts two dependencies in
i have a main Activity called Main which has onActivityResult Method. protected void onActivityResult(int
I have class with a member function that takes a default argument. struct Class

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.