This is a migrated thread and some comments may be shown as answers.

Threading Issue : RadMap Inside Window Form Element Host

1 Answer 84 Views
Map
This is a migrated thread and some comments may be shown as answers.
Sanjay
Top achievements
Rank 1
Sanjay asked on 09 Feb 2015, 09:01 AM
Hi There

I'm calling WPF RadMap usercontrol inside Window form usercontrol using elementHost. But while calling using UI Virtualization it gives error as shown below.The below code works fine in standalone WPF usercontrol.

MapShapeDataVirtualizationSource map = new MapShapeDataVirtualizationSource();
               AsyncShapeFileReader reader = new AsyncShapeFileReader();
               reader.ToolTipFormat = "FieldName";
               reader.Source = new Uri(rShape["path"].ToString() + ".shp", UriKind.RelativeOrAbsolute);
               reader.DataSource = new Uri(rShape["path"].ToString() + ".dbf", UriKind.RelativeOrAbsolute);
               map.Reader = reader;
               map.ReadAsync(); // Give the error .See the attached Error screen shot.
               map.ClearCache = false;
               vLayer.VirtualizationSource = map;
               vLayer.UseBitmapCache = false;
               vLayer.RefreshVirtualSource();
               this.radMapNaveo.Items.Add(vLayer);

The below code works.
AsyncShapeFileReader reader = new AsyncShapeFileReader();
               reader.ToolTipFormat = "FieldName";
               reader.Source = new Uri(rShape["path"].ToString() + ".shp", UriKind.RelativeOrAbsolute);
               reader.DataSource = new Uri(rShape["path"].ToString() + ".dbf", UriKind.RelativeOrAbsolute);                    
               vLayer.Reader = reader;
               vLayer.UseBitmapCache = false;
               vLayer.RefreshVirtualSource();
               this.radMapNaveo.Items.Add(vLayer);

 
Later I found that this is threading issue related to STA architecture, as it also throw the error "The calling thread must be STA,because many UI components require this". See the attachment.

Cheers. 

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 11 Feb 2015, 08:13 AM
Hi Sanjay,

In Winforms you can work with UI controls only from the main UI thread. ReadAsync() uses internally BackgroundThreads which is not supported when you are in ElementHost. 
What can you do is to wait for the AsycReader to read all shape, use ReadShapeDataCompleted event and add the RadMap in the ElementHost when read is completed. While reading you can have some kind of BusyIndicator / Waiting Bar.
We hope this helps you proceed further.

Regards,
Petar Mladenov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Map
Asked by
Sanjay
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or