private void DrawPreview() { if (WmsRasterLayer == null) { InitializeWmsRasterLayer(); } Bitmap previewBitmap = null; MemoryStream bitmapMemory = null; try { WmsRasterLayer.Open(); WmsRasterLayer.TimeoutInSecond = 30; WmsRasterLayer.ActiveLayerNames.Clear(); WmsRasterLayer.ActiveLayerNames.Add(SelectedLayer.Name); MapEngine mapEngine = new MapEngine(); mapEngine.StaticLayers.Add(WmsRasterLayer); mapEngine.CurrentExtent = WmsRasterLayer.GetBoundingBox(); previewBitmap = new Bitmap(125, 125); mapEngine.DrawStaticLayers(previewBitmap, GeographyUnit.DecimalDegree); bitmapMemory = new MemoryStream(); previewBitmap.Save(bitmapMemory, ImageFormat.Png); } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); Application.Current.Dispatcher.BeginInvoke(new Action(() => { SendMessageBox(ex.Message, "Warning"); })); } finally { if (previewBitmap != null) { previewBitmap.Dispose(); } var action = new Action(() => { if (bitmapMemory == null || bitmapMemory.Length == 0) { PreviewSource = GetDefaultPreview(); } else { PreviewSource = ToImageSource(bitmapMemory); } IsBusy = false; }); if (Application.Current != null) { Application.Current.Dispatcher.BeginInvoke(action); } else { action(); } } }