void BrowseContentDialog_ResourceSelected(object sender, ResourceSelectedEventArgs e) { if (e == null) { return; } IDataSourceWithResources dataSource = DataSourceProvider.CreateNewDataSourceForConnectionType(e.ConnectionType) as IDataSourceWithResources; if (dataSource == null) { return; } Resource resource = e.Resource; if (resource == null) { return; } // Notify listeners that a resource has been selected OnResourceSelected(e); dataSource.CreateLayerCompleted += (o, args) => { Dispatcher.BeginInvoke((Action) delegate { OnLayerAdded(new LayerAddedEventArgs() { Layer = args.Layer }); }); }; dataSource.CreateLayerFailed += (o, args) => { Dispatcher.BeginInvoke((Action) delegate { Logger.Instance.LogError(args.Exception); OnLayerAddFailed(args); return; }); }; dataSource.CreateLayerAsync(resource, Map != null ? Map.SpatialReference : BrowseContentDialog.MapSpatialReference, null); // NOTE:- layer can only be instantiated on the UI thread because it has a Canvas (UI) element }