I'm really going crazy, I'm not able to use any awaits for the async methods below...
It's a UWP application, the code below is inside a Core project based on .NET Standard 2.0.
I've included the entire code, it's obviously unfinished. The most odd behavior is the BitmapDecoder
says there is no GetAwaiter
(are you missing a using
?), when I remove the await, it says I need to add an await :D
using System.Threading.Tasks;
using Windows.Storage.Streams;
using Windows.UI.Xaml.Media.Imaging;
using Windows.Graphics.Imaging;
namespace Namespace...
{
public class CacheService
{
public async Task<BitmapImage> GetCachedImage(long? productId, long? imageId)
{
return null;
}
public async Task<BitmapImage> SaveImage(byte[] imageBytes, long? productId, long? imageId)
{
BitmapImage image = new BitmapImage();
using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
{
using (DataWriter writer = new DataWriter(stream))
{
writer.WriteBytes(imageBytes);
writer.StoreAsync();
writer.FlushAsync();
writer.DetachStream();
}
stream.Seek(0);
image.SetSourceAsync(stream);
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
}
return image;
}
}
}