I'm using Flurl to make requests. Currently I have the following code and everything works fine:
public class Request()
{
public async Task<Bitmap> GetImage(string url)
{
using (var client = new Url(url)
{
var content = await client.GetStringAsync();
//return as image
}
}
}
And on the main UI thread I do:
public async void GetImages()
{
for (int i = 0; i < someCounter; i++)
{
var img = await myRequest.GetImage(url);
Thread.Sleep(100);
}
}
The above works but the UI thread sleeps for a while and I wanted to do the above within a task. So I did:
public async void GetImages()
{
await Task.Run(async () =>
{
for (int i = 0; i < someCounter; i++)
{
var img = await myRequest.GetImage(url);
Thread.Sleep(100);
}
});
}
However, with the above, the code stops at await client.GetStringAsync();
. There's no exception, the code either stop execution there or waits for something.
Is what I'm trying to do correct or is there a better way. If it's correct, why does the inner await never completes?