Я пытаюсь загрузить несколько фотографий из Интернета асинхронно. Я построил метод GetImageBitmapFromUrl
следующимиспользуя ожидание внутри сеттеров
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;
}
Я сейчас пытаюсь вызвать этот метод в моем инкубаторе
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; }
}
Но я получаю эту ошибку
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'.
Как могу ли я пометить установщика с помощью модификатора «async»?