I'm trying to download some pictures from the internet Asynchronously. I've built the GetImageBitmapFromUrl
method as following
async Task<Bitmap> GetImageBitmapFromUrl(string url)
{
Bitmap imageBitmap = null;
try
{
using (var webClient = new WebClient())
{
var imageBytes = await webClient.DownloadStringTaskAsync(url);
if (imageBytes != null && imageBytes.Length > 0)
{
imageBitmap = BitmapFactory.DecodeByteArray(Encoding.ASCII.GetBytes(imageBytes), 0, imageBytes.Length);
}
}
}
catch
{
//Silence is gold.
}
return imageBitmap;
}
I'm now trying to call this method inside my setter
List<string> _pictures;
Bitmap[] imageBitmap;
int currentPic = 0;
ImageView gellaryViewer;
public List<string> pictures
{
set
{
if (value.Count == 0)
{
gellaryViewer.Visibility = ViewStates.Gone;
}
else
{
gellaryViewer.Visibility = ViewStates.Visible;
_pictures = value;
currentPic = 0;
imageBitmap = new Bitmap[value.Count];
for (int i = 0; i < value.Count; i++)
//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'.
imageBitmap[i] = await GetImageBitmapFromUrl(value[i]);
displayPic();
}
}
get { return _pictures; }
}
But I'm getting this error
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'.
How can I mark the setter with the 'async' modifier?