public void RefreshIcon() { if (CommandModel.IsChecked) { Icon = null; } if (CommandModel.HeaderIconExtractor != null) { byte[] bytes = AsyncUtils.RunSync(() => CommandModel.HeaderIconExtractor.GetIconBytesForModelAsync(CommandModel, CancellationToken.None)); if (bytes != null && bytes.Length > 0) { Icon = new System.Windows.Controls.Image() { Source = BitmapSourceUtils.CreateBitmapSourceFromBitmap(bytes), MaxWidth = 16, MaxHeight = 16 } } ; } }
private void loadIcon() { //var icon = AsyncUtils.RunSync(() => _iconExtractSequences.Last().GetIconForModelAsync(EntryModel, CancellationToken.None)); //Icon = icon; Task loadIconTask = Task.Run <BitmapSource>(async() => { var sequence = _iconExtractSequences.ToList(); byte[] bytes = await _iconExtractSequences.Last() .GetIconBytesForModelAsync(EntryModel, CancellationToken.None); if (bytes != null && bytes.Length > 0) { return(BitmapSourceUtils.CreateBitmapSourceFromBitmap(bytes)); } else { return(null); } }) .ContinueWith((tsk) => { if (tsk.IsCompleted && !tsk.IsFaulted && tsk.Result != null) { Icon = tsk.Result; } ; }, TaskScheduler.FromCurrentSynchronizationContext() ); //for (int i = 1; i < sequence.Count - 1; i++) //{ // loadIconTask = loadIconTask.ContinueWith<ImageSource>( // (tsk) => AsyncUtils.RunSync(() => sequence[i].GetIconForModelAsync(EntryModel))) // .ContinueWith((tsk) => // { // if (tsk.IsCompleted && !tsk.IsFaulted && tsk.Result != null) // Icon = tsk.Result; // }, TaskScheduler.FromCurrentSynchronizationContext() // ); //} }