Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Xamarin.Forms Portable - where is InvokeOnMainThread ?

$
0
0

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
      }

Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>