Ich versuche, einige Bilder aus dem Internet asynchron herunterladen. Ich habe die GetImageBitmapFromUrl
Methode folgendmit erwarten innerhalb Setter
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;
}
gebaut ich jetzt versuchen, diese Methode in meinem Setter zu nennen
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; }
}
Aber ich bekomme diese Fehlermeldung
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'.
Wie kann ich den Setter mit dem Modifizierer 'async' markieren?