I am new to Xamarin Android and i am developing just simple app for fetching and displaying image from server. Here is my code-
public void testWCF2()
{
var imgView = FindViewById<ImageView>(Resource.Id.imageView123);
using(var bm = await GetImageFromUrl(@"http://xamarin.com/content/images/pages/forms/example-app.png")) //At this line an error is showing The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.
imgView.SetImageBitmap(bm);
}
private async Task<Bitmap> GetImageFromUrl(string url)
{
using(var client = new HttpClient())
{
var msg = await client.GetAsync(url);
if (msg.IsSuccessStatusCode)
{
using(var stream = await msg.Content.ReadAsStreamAsync())
{
var bitmap = await BitmapFactory.DecodeStreamAsync(stream);
return bitmap;
}
}
}
return null;
}
Someone please help me.
Thanks