Skip to content

Commit

Permalink
fix dispose issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vb2ae committed Nov 23, 2023
1 parent b2c9409 commit ec93b3f
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

namespace AstronomyPictureOfTheDay.Sample.Avalonia.Converters
{
Expand All @@ -24,20 +23,17 @@ public class BitmapConverter : IValueConverter

if (value is string rawUri && targetType.IsAssignableFrom(typeof(Bitmap)))
{
Bitmap? spaceImage = null;
var getImageTask = Task.Run(async () =>

using (HttpClient client = new HttpClient())
{
using (HttpClient client = new HttpClient())
Bitmap? spaceImage = null;
using (HttpResponseMessage response = client.GetAsync(rawUri).GetAwaiter().GetResult())
using (Stream stream = response.Content.ReadAsStreamAsync().GetAwaiter().GetResult())
{
using (HttpResponseMessage response = await client.GetAsync(rawUri))
using (Stream stream = await response.Content.ReadAsStreamAsync())
{
spaceImage = new Bitmap(stream);
}
spaceImage = new Bitmap(stream);
}
});
getImageTask.Wait();
return spaceImage;
return spaceImage;
}
}

throw new NotSupportedException();
Expand Down

0 comments on commit ec93b3f

Please sign in to comment.