public ActionResult GetResourceImage(string id) { using (var emkService = ServiceFactory.GetServiceWrapper<IEmkService>()) { IList<EmkResource> emkResources = emkService.Instance.GetAllResources(); EmkResource resource = emkResources.FirstOrDefault(x => x.Id == id); if (resource == null) { return null; } using (FileTransferServiceClient client = new FileTransferServiceClient()) { try { Stream content = client.GetFileFromPath(resource.IconFileName); if (content != null) { return File(content, GetMimeType(resource.IconFileName)); } } catch (IOException ex) { // This exception is totally OK. No image will be displayed. } catch (AssertionFailedException) { // This exception is totally OK. No image will be displayed. } } } return null; }
private void LoadIconAsync() { ThreadPool.QueueUserWorkItem(w => { using (FileTransferServiceClient client = new FileTransferServiceClient()) { try { Stream content = client.GetFileFromPath(EmkResourceItem.IconFileName); if (content != null) { ImageSource icon = BitmapFrame.Create(content); Application.Current.Dispatcher.Invoke((Action)(() => { Icon = icon; OnPropertyChanged("Icon"); })); } } catch (AssertionFailedException) { // Occurs if the path is empty. } catch (IOException) { // This exception is totally OK. No image will be displayed. } catch (Exception ex) { Logger.Instance.LogException(this, ex); } } }); }