I tried to use HttpClient in Xamarin.Forms Portable debugging on Windows Phone.
First, if I tried to wait for result then it hangs forever.
Then I decided to do asynchronously, it gets response, but I cannot assign the result to the GUI, text of label.
The docs say that I should use InvokeOnMainThread.
Where is it?
I have found it only here:
http://iosapi.xamarin.com/?link=T:MonoTouch.Foundation.NSObject/M/InvokeOnMainThread
As I understand this is for iOS only. What should I do then for shared code or Windows Phone?
void button_3_Clicked(object sender,EventArgs e)
{
var client = new System.Net.Http.HttpClient();
var task = client.GetAsync("http://api.usa.gov/jobs/search.json?query=nursing+jobs")
.ContinueWith((taskwithresponse) =>
{
var response = taskwithresponse.Result;
var jsonString = response.Content.ReadAsStringAsync().ContinueWith( (task1) =>
{
string str_response= task1.Result;
//InvokeOnMainThread(() => { // <---- where is it ?
// bottom_label.Text=str_response;
//});
bottom_label.Text=str_response;
DisplayAlert("main_page", bottom_label.Text, "OK","Cancel");
});
});
// task.Wait(); - hangs forever here
}