Threading Issue : RadMap Inside Window Form Element Host

2 posts, 0 answers
  1. Sanjay
    Sanjay avatar
    21 posts
    Member since:
    Jun 2014

    Posted 09 Feb 2015 Link to this post

    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. 
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 11 Feb 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top