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.
You want a callback from the request once it is completed. This is supported i.e. by the
WebClient:Edit:
You could pass in a delegate to your
reqclass that you pass the result string (also note the naming guidelines, should be all Uppercase), so change the method signature as follows:And change the calling code to: