I working on image loader library for Windows Phone 8+ applications, and of course it supports caching on disk.
So, I need to save image on disk asynchronously without awaiting result:
// Async saving to the storage cache without await
// ReSharper disable once CSharpWarnings::CS4014
Config.StorageCacheImpl.SaveAsync(imageUrl, downloadResult.ResultStream)
.ContinueWith(
task =>
{
if (task.IsFaulted || !task.Result)
{
Log("[error] failed to save in storage: " + imageUri);
}
}
);
As you can see, SaveAsync()
is async method and it returns Task<bool>
, where bool
result is true if image was saved.
The problem is that compiler shows warning because I am not awaiting the result of the async method, but, I do not need to await it, i need to return downloaded image to the user code as fast as it possible, after invoke of SaveAsync()
I return downloaded image.
So I am caching image to the IsolatedStorageFile asynchronously and moreover — it does not matter, will it be cached or not, because if not — JetImageLoader will load it again.
Is it possible to disable this warning?
P.S. if you want to see JetImageLoader sources, I can give you a link to GitHub.