I wanted to fetch and display data but its not working and after this line
var response = await client.GetAsync(uri).ConfigureAwait(false);
code never executed not even throw an exception
public async Task<List<Restresponse>> RefreshDataAsync()
{
var Items = new List<Restresponse>();
try
{
HttpClient client = new HttpClient();
var uri = new Uri(string.Format("https://jsonplaceholder.typicode.com/posts", string.Empty));
var response = await client.GetAsync(uri).ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); ;
// Items = JsonConvert.DeserializeObject<List<TodoItem>>(content);
}
}
catch (Exception e)
{
Log.WriteLine(LogPriority.Debug, "EXception from restservice", e.Message);
}
return Items;
}
and i have called this functiion in OncreateView in fragment
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.Inflate(Resource.Layout.recycleview, container, false);
mRecyclerView = view.FindViewById<RecyclerView>(Resource.Id.recyclerView);
mLayoutManager = new LinearLayoutManager(this.Activity);
mRecyclerView.SetLayoutManager(mLayoutManager);
// Prepare the data source:
listItem = new List<Restresponse>();
try
{
listItem = RefreshDataAsync().Result;
// Instantiate the adapter and pass in its data source:
mAdapter = new RecycleViewAdapter(listItem, this.Activity);
// Plug the adapter into the RecyclerView:
mRecyclerView.SetAdapter(mAdapter);
}
catch (System.Exception e)
{
Log.WriteLine(LogPriority.Debug, "EXception from fragmenbt", e.Message);
}
return view;
}
RefreshDataAsync()being called? If you are mixing blocking and async calls then most likely you are experiencing a deadlock.RefreshDataAsync().Resultis causing a deadlock do not mix blocking calls like.Resultwith async-await code as they tend to lead to deadlocks