private void openImageBGThread(String filename, bool applyUpdate) { try { using (Stream imageStream = resourceProvider.openFile(filename)) { var image = new FreeImageBitmap(imageStream); int left = 0; int top = 0; int width = 8; float aspect = (float)image.Height / image.Width; int height = (int)((float)imagePanel.Width * aspect); if (height < imagePanel.Height) { width = imagePanel.Width; top = (imagePanel.Height - height) / 2; } else { aspect = (float)image.Width / image.Height; height = imagePanel.Height; width = (int)((float)imagePanel.Height * aspect); left = (imagePanel.Width - width) / 2; } ThreadManager.invoke(() => { try { if (NotDisposed) { imagePreview.setPosition(left, top); imagePreview.setSize(width, height); imageAtlas.ImageSize = new IntSize2(width, height); String imageKey = imageAtlas.addImage(Key, image); imagePreview.setItemResource(imageKey); loadingLabel.Visible = false; if (applyUpdate) { this.fireChangesMade(); this.fireApplyChanges(); } } } finally { image.Dispose(); } this.fireChangesMade(); }); } } catch (Exception ex) { Logging.Log.Error("Could not load image '{0}'. Reason: {1}", filename, ex.Message); } }