2

In this case, when an ArcGIS Pro project is opened, non map panes are active. I would like the map pane to be activated on the click of the button as proceeding code requires the MapView.Active to not be null. Inside the OnClick function, I am attempting to activate the map pane but it is not activated in time. It's activated later on which causes errors as the active map view returns null for code that runs after this.

internal class MyDockpane_ShowButton : Button
{
    internal static void activatePane()
    {
        var mapPane = FrameworkApplication.Panes.OfType<IMapPane>().First() as Pane;
        mapPane.Activate();
    }
    protected override void OnClick()
    {
        activatePane()
        MyDockpaneViewModel.Show();            
    }
}

I believe that I need to await the activatePane() function so I re-wrote the code as below:

internal class MyDockpane_ShowButton : Button
{
    internal static async Task activatePane()
    {
        await QueuedTask.Run(() =>
        {
            var mapPane = FrameworkApplication.Panes.OfType<IMapPane>().First() as Pane;
            mapPane.Activate();
        });
    }
    protected override async void OnClick()
    {
        await activatePane();
        MyDockpaneViewModel.Show();            
    }
}

With the new code, I get System.InvalidOperationException: "The calling thread cannot access this object because a different thread owns it". What am I doing wrong here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.