Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD) using mapsui pin

0

I'm actually using the Mapsui Nugget for using a map in my application. So, I create a page :

    <ContentPage.Content>
        <mapsui:MapView Content="{Binding MapView}">
        </mapsui:MapView>
    </ContentPage.Content>`

Using the MVVM pattern, there is my ViewModel :

    public CartoGlobalPageViewModel()
    {
      Title = "Cartographie";
      MapView = 
      Xamarin.Forms.DependencyService.Get<ICartographie().GenerateMap();
    }

As you can see, I'm using the Xamarin dependency injection.

This works perfectly, there is my GenerateMap method :

    public MapView GenerateMap()
    {
       m = new MapView();
       IGNConfig.LicenceKey = "aKey";
       IGNConfig.Credential = new System.Net.NetworkCredential("Login", "password");
       MapsuiIGNDataProvider ignDataProvider = MapsuiIGNDataProvider.Instance;
       m.Map.Layers.Add(ignDataProvider.CreateTileLayer());
       //var layer = GenerateIconLayer();
       //m.Map.Layers.Add(layer);
       //IGNMapLayer _MapLayer = new IGNMapLayer();
       //ignDataProvider.MapLayer = _MapLayer;
       //ignDataProvider.Zoom = 12;
       m.MapClicked += CreatePin; 
       return m;
    }

Actually, my map appears perfectly, but when I wan't to put a pin on my map, (which is created by the MapCliked event with the CreatePin function).

There is the function :

`public void CreatePin(object sender, MapClickedEventArgs e)
 {
    m.Pins.Add(new Pin(m)
    {
        Position = new Position(0, 0),
        Type = PinType.Pin,
        Label = "Zero point",
        Address = "Zero point",
    });  
}`

And now, when I click one time, a pin appears, but if I click another time, I've got this error :

        System.Exception HResult=0x8001010E Message=L’application a appelé une 
        interface qui était maintenue en ordre pour un thread différent. 
        (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)) 
        Source=Windows Arborescence des appels de procédure : 
        à Windows.UI.Xaml.Application.get_Resources() 
        à Xamarin.Forms.Platform.UWP.FontExtensions.GetFontSize(NamedSize size)
    Xamarin.Forms.Platform.UWP.WindowsBasePlatformServices.GetNamedSize(NamedSize size, Type targetElementType, Boolean useOldSizes) 
        à Xamarin.Forms.Label.Xamarin.Forms.Internals.IFontElement.FontSizeDefaultValue 
        Creator() 
        à Xamarin.Forms.FontElement.FontSizeDefaultValueCreator(BindableObject 
        bindable) 
        à Xamarin.Forms.BindableObject.CreateAndAddContext(BindableProperty 
        property) 
        à Xamarin.Forms.BindableObject.GetValues(BindableProperty property0, 
        BindableProperty property1)
        à Xamarin.Forms.FontElement.OnFontFamilyChanged(BindableObject bindable, 
        Object oldValue, Object newValue) 
        à Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, 
        BindablePropertyContext context, Object value, Boolean currentlyApplying, 
        SetValueFlags attributes, Boolean silent) 
        à Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, 
        Object value, SetValueFlags attributes, SetValuePrivateFlags 
        privateAttributes) 
        à Xamarin.Forms.BindableObject.SetValue(BindableProperty property, Object 
        value, Boolean fromStyle, Boolean checkAccess) 
        à Mapsui.UI.Objects.Callout..ctor(MapControl mapControl) à 
        Mapsui.UI.Forms.MapView.CreateCallout(Position position) 
        à Mapsui.UI.Forms.Pin.get_Callout() à 
        Mapsui.UI.Forms.MapView.HandlerTap(Object sender, TappedEventArgs e) 
        à Mapsui.UI.Forms.MapControl.OnSingleTapped(Point screenPosition) 
        à Mapsui.UI.Forms.MapControl.<>c__DisplayClass37_0.<OnTouch>b__5(Object 
        l) 
        à System.Threading.TimerQueueTimer.<>c.<.cctor>b__22_0(Object state) 
        à System.Threading.ExecutionContext.RunInternal(ExecutionContext 
        executionContext, ContextCallback callback, Object state) 
        à System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
        à System.Threading.ExecutionContext.RunInternal(ExecutionContext 
        executionContext, ContextCallback callback, Object state) 
        à System.Threading.TimerQueueTimer.CallCallback() 
        à System.Threading.TimerQueueTimer.Fire() 
        à System.Threading.TimerQueue.FireNextTimers() 
        à System.Threading.TimerQueue.AppDomainTimerCallback(Int32 id)

I already try all this solutions:

    Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher 
        .RunAsync(CoreDispatcherPriority.Normal,
        () =>
        {
            // Your UI update code goes here!
        }
        );

_____________

    Application.Current.Dispatcher.Invoke((Action)(() => myCode));

_____________

    await Windows.ApplicationModel.Core.CoreApplication
    .MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
    () =>
    {
    // Your UI update code goes here!
    }
    ).AsTask();

_____________
    Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
    {
    m.Pins.Add(new Pin(m)
    {
        Position = new Position(0, 0),
        Type = PinType.Pin,
        Label = "Zero point",
        Address = "Zero point",
    });
    });

Hope you can help me, thank's

c#
multithreading
dictionary
interface
mapsui
asked on Stack Overflow Aug 27, 2019 by Alex

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0