コード例 #1
0
 static async void SetUriSourceAsync(BitmapSource image, Uri uri)
 {
     try
     {
         using (var inputStream = await httpClient.GetInputStreamAsync(uri))
         using (var stream = new InMemoryRandomAccessStream())
         {
             await RandomAccessStream.CopyAsync(inputStream, stream);
             stream.Seek(0);
             await image.SetSourceAsync(stream);
         }
     }
     catch
     {
         store.Value.Remove(uri);
     }
 }
コード例 #2
0
        private async Task<bool> LoadImageFromStream(Tile tile, BitmapSource image, IRandomAccessStream stream)
        {
            var completion = new TaskCompletionSource<bool>();

            var action = image.Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                async () =>
                {
                    try
                    {
                        await image.SetSourceAsync(stream);
                        tile.SetImage(image, true, false);

                        completion.SetResult(true);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                        tile.SetImage(null);

                        completion.SetResult(false);
                    }
                });

            return await completion.Task;
        }