title: Image Rotation while fetching data [Xamrin forms] EDITED WITH NEW ERROR MESSAGE Only the original thread that created a view hierarchy
body: <p>How can I make an image rotate while I fetch data from a web server ?</p>
  <pre><code>   private async void FetchDataAsync(object sender, EventArgs e)
      {
          ImageBox.IsVisible = true;
          rotation = new Animation(v =&gt; ImageBox.Rotation = v, 0, -360);
          rotation.Commit(this, &quot;rotate&quot;, 5, 1000, Easing.Linear, (v, c) =&gt; ImageBox.Rotation = 0, () =&gt; true);using (
          
           var httpC = new HttpClient())
              {
                
                  if (!string.IsNullOrEmpty(url))
                  {
                      var result = httpC.GetAsync(finalUrl).GetAwaiter().GetResult();
                      var results = result.Content.ReadAsStringAsync();
                       .
                       .
                       .
                       .
                       .
  
                       etc
                }
           }
       }
  </code></pre>
  <p>If I remove the client part the Image spins perfectly so the rotation works, but why does it not work when I am fetching using http client ? how to make it run while the thread is busy ?</p>
  <p>OK SO HERE IS THE EDITED PART, After some research I managed to get it spinning, and use async and await.. but now whenever I touch the phone screen while its doing the work in the background I get this error
  &quot;Only the original thread that created a view hierarchy can touch its views.'&quot;</p>
  <pre><code>        private async void BtnOpenServicesPageClicked(object sender, EventArgs e)
      {
        //  Device.BeginInvokeOnMainThread(() =&gt; { RunRotation(); });
          RunRotation();
          DisbaleUI();
          var userName = TxtUserName.Text;
          var password = TxtPassword.Text;
  
          if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
          {
            await  DisplayAlert(&quot;Missing Credentials&quot;, &quot;User name and password are required fields&quot;, &quot;Ok&quot;);
              return;
          }
  
        
  
          var url = &quot;The Url To Be USed&quot;;
          var builder = new UriBuilder(url);
          builder.Port = 0000;
          var query = HttpUtility.ParseQueryString(builder.Query);
          query[&quot;username&quot;] = &quot;username&quot;;
          query[&quot;password&quot;] = &quot;password&quot;;
          builder.Query = query.ToString();
  
          string finalUrl = builder.ToString();
          var services=await Task.Run( () =&gt; RunHttpRequestAsync(finalUrl));
         
          var servicesPage= new ServicesMainPage(services);
          EnableUI();
          await Navigation.PushModalAsync(new NavigationPage(obcMapsPage));
      }
  
     private async Task&lt;List&lt;NNWServices&gt;&gt; RunHttpRequestAsync(string finalUrl)
      {
          var services = new List&lt;NNWServices&gt;();
  
          try
          {
          
              using (var httpC = new HttpClient())
              {
  
                  if (!string.IsNullOrEmpty(finalUrl))
                  {
                      var result = httpC.GetAsync(finalUrl).Result;
                      var results = result.Content.ReadAsStringAsync();
  
  
                      var responseDictionary = JsonConvert.DeserializeObject&lt;Dictionary&lt;string, object&gt;&gt;(results.Result);
                      var userInfo = responseDictionary[&quot;User&quot;];
                      var allUSerInfo = JsonConvert.DeserializeObject&lt;Dictionary&lt;string, object&gt;&gt;(userInfo.ToString());
                      var userNAme = allUSerInfo[&quot;UN&quot;].ToString();
                      var passWord = allUSerInfo[&quot;PW&quot;].ToString();
  
  
                      var item = responseDictionary[&quot;SINFO&quot;].ToString();
  
                      var allServerInfo = JsonConvert.DeserializeObject&lt;Dictionary&lt;string, object&gt;&gt;(item);
  
  
                      var servicesInside = allServerInfo[&quot;Services&quot;].ToString();
                      var crntSrvces = JsonConvert.DeserializeObject&lt;List&lt;NNWServices&gt;&gt;(servicesInside);
  
                      foreach (var srv in crntSrvces)
                      {
                          srv.UserName = userNAme;
                          srv.Password = passWord;
                      }
                      services.AddRange(crntSrvces);
                  }
              }
  
          }
          catch (Exception ex)
          {
              this.AbortAnimation(&quot;rotate&quot;);
              ImageBox.IsVisible = false;
              return services;
          }
          this.AbortAnimation(&quot;rotate&quot;);
          ImageBox.IsVisible = false;
          return services;
      }
  </code></pre>
  <p>Any help would be appreciated I am very new to Xamarin</p>