<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: MessageBox blocks UI and map window in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1091819#M7064</link>
    <description>&lt;P&gt;To add the overlay control to the active map you can use this method:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/#topic17211.html" rel="nofollow" target="_blank"&gt;MapView.AddOverlayControl&lt;/A&gt;. This method takes a MapViewOverlayControl as its parameter.&lt;/P&gt;&lt;DIV class="highlight highlight-source-cs position-relative"&gt;&lt;PRE&gt;   &lt;SPAN class="pl-k"&gt;public&lt;/SPAN&gt; &lt;SPAN class="pl-k"&gt;void&lt;/SPAN&gt; &lt;SPAN class="pl-en"&gt;AddOverlayControl&lt;/SPAN&gt;(&lt;SPAN class="pl-k"&gt;IMapViewOverlayControl&lt;/SPAN&gt; &lt;SPAN class="pl-en"&gt;overlayControl&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;P&gt;Let me know if this works, otherwise I will create a sample snippet.&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 24 Aug 2021 17:20:00 GMT</pubDate>
    <dc:creator>Wolf</dc:creator>
    <dc:date>2021-08-24T17:20:00Z</dc:date>
    <item>
      <title>MessageBox blocks UI and map window</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1091261#M7060</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;in my code I'm continously updating a map overlay. At some point of time I raise a MessageBox&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(
                            message,
                            "Kursverfolgung",
                            MessageBoxButton.OK,
                            MessageBoxImage.Information,
                            MessageBoxResult.OK
                        );&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;This makes my map window freezing and my overlay position don't gets updated anymore. Maybe it's a problem with WPF MessageBox itself but is there a way to show an into message to the user without blocking the UI?&lt;BR /&gt;&lt;BR /&gt;There is no user interaction necessary. The info pane can disappear by itself let's say after 5 seconds.&lt;/P&gt;&lt;P&gt;Can I create a invisible pane, position it over the map view and make it visible for a short amount of time?&lt;BR /&gt;&lt;BR /&gt;Thanks for any help.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 15:13:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1091261#M7060</guid>
      <dc:creator>RichardReinicke</dc:creator>
      <dc:date>2021-08-23T15:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: MessageBox blocks UI and map window</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1091304#M7061</link>
      <description>&lt;P&gt;Hi, the MapView Overlay Control would likely fit your needs.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Map-Exploration#mapview-overlay-control" target="_blank"&gt;https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Map-Exploration#mapview-overlay-control&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 17:32:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1091304#M7061</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-08-23T17:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: MessageBox blocks UI and map window</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1091631#M7063</link>
      <description>&lt;P&gt;Hello&amp;nbsp;@Anonymous User,&lt;BR /&gt;&lt;BR /&gt;thank you for your link. I remembered there was something like that.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;But for some reason the&amp;nbsp;MapViewOverlayControl is not visible for me. I also reinstalled the .Net SDK templates and utilities for VS2017 and tried with the embeddable control template but same effect. Maybe it's a thread problem again?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;_handleGpsDataThread = new Thread(StartHandleGpsDataLoop);
_handleGpsDataThread.Priority = ThreadPriority.BelowNormal;
_handleGpsDataThread.Start();

private async void StartHandleGpsDataLoop()
{
    await HandleNewGpsDataAsync(GpsMessageBuffer.Last());
}

private async Task HandleNewGpsDataAsync(GpsData newGpsData)
{
    await QueuedTask.Run(() =&amp;gt;
    {
        try
        {
            ...
            var targetCourse = 
                GetDistanceToCurrentTarget(workstationLocation, 2).Result;
            ...
        }
        catch (EndOfRouteException eore)
        {
            var courseEndMessageControl = 
                new CourseEndMessageControlView();
            var mapViewOverlayControl =
                new MapViewOverlayControl(
                    courseEndMessageControl,
                    true, 
                    true, 
                    true,
                    OverlayControlRelativePosition.TopLeft);
                        
            MapView.Active.AddOverlayControl(mapViewOverlayControl);
        }
    }
}

private Task&amp;lt;Course&amp;gt; GetDistanceToCurrentTarget(MapPoint currentLocation, int decimalPrecision)
{
    return QueuedTask.Run(() =&amp;gt;
    {
        ...
        throw new EndOfRouteException(
            "You reached the end of the current route.");
        ...
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;UserControl x:Class="AddIn.Gps.UserControls.CourseEndMessageControlView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:ui="clr-namespace:AddIn.Gps.UserControls"
             xmlns:extensions="clr-namespace:ArcGIS.Desktop.Extensions;assembly=ArcGIS.Desktop.Extensions"
             mc:Ignorable="d" 
             d:DesignHeight="75" d:DesignWidth="415"
             d:DataContext="{Binding Path=ui.CourseEndMessageControlViewModel}"&amp;gt;
            &amp;lt;UserControl.Resources&amp;gt;
        &amp;lt;ResourceDictionary&amp;gt;
            &amp;lt;ResourceDictionary.MergedDictionaries&amp;gt;
                &amp;lt;extensions:DesignOnlyResourceDictionary Source="pack://application:,,,/ArcGIS.Desktop.Framework;component\Themes\Default.xaml"/&amp;gt;
            &amp;lt;/ResourceDictionary.MergedDictionaries&amp;gt;
        &amp;lt;/ResourceDictionary&amp;gt;
    &amp;lt;/UserControl.Resources&amp;gt;
    &amp;lt;Grid&amp;gt;
        &amp;lt;Border Background="White" BorderBrush="LightSkyBlue" BorderThickness="2"&amp;gt;
            &amp;lt;StackPanel Orientation="Vertical" &amp;gt;
                &amp;lt;TextBlock FontSize="20" FontWeight="Medium" Margin="20"&amp;gt;
                    Sie haben den letzten Zielpunkt erreicht.
                &amp;lt;/TextBlock&amp;gt;
            &amp;lt;/StackPanel&amp;gt;
        &amp;lt;/Border&amp;gt;
    &amp;lt;/Grid&amp;gt;
&amp;lt;/UserControl&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any suggestion how I can make the overlay appear?&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 09:45:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1091631#M7063</guid>
      <dc:creator>RichardReinicke</dc:creator>
      <dc:date>2021-08-24T09:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: MessageBox blocks UI and map window</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1091819#M7064</link>
      <description>&lt;P&gt;To add the overlay control to the active map you can use this method:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/#topic17211.html" rel="nofollow" target="_blank"&gt;MapView.AddOverlayControl&lt;/A&gt;. This method takes a MapViewOverlayControl as its parameter.&lt;/P&gt;&lt;DIV class="highlight highlight-source-cs position-relative"&gt;&lt;PRE&gt;   &lt;SPAN class="pl-k"&gt;public&lt;/SPAN&gt; &lt;SPAN class="pl-k"&gt;void&lt;/SPAN&gt; &lt;SPAN class="pl-en"&gt;AddOverlayControl&lt;/SPAN&gt;(&lt;SPAN class="pl-k"&gt;IMapViewOverlayControl&lt;/SPAN&gt; &lt;SPAN class="pl-en"&gt;overlayControl&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;P&gt;Let me know if this works, otherwise I will create a sample snippet.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 24 Aug 2021 17:20:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1091819#M7064</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2021-08-24T17:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: MessageBox blocks UI and map window</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1091825#M7065</link>
      <description>&lt;P&gt;Here's an existing overlay control snippet that may help as well:&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-MapExploration#mapview-overlay-control" target="_blank"&gt;https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-MapExploration#mapview-overlay-control&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 17:35:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1091825#M7065</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-08-24T17:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: MessageBox blocks UI and map window</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1092112#M7067</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/12882"&gt;@Wolf&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I added my relevant code under the first answer above. From my point of view that looks like what the documentation links contain.&lt;/P&gt;&lt;P&gt;We are at SDK version 2.4 and Pro version 2.4.1, due to customer decisions. Makes this a difference? Is my thread/task management the problem?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 07:08:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1092112#M7067</guid>
      <dc:creator>RichardReinicke</dc:creator>
      <dc:date>2021-08-25T07:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: MessageBox blocks UI and map window</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1092188#M7070</link>
      <description>&lt;P&gt;I will try to get this to work with 2.4.1.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 13:38:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1092188#M7070</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2021-08-25T13:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: MessageBox blocks UI and map window</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1092189#M7071</link>
      <description>&lt;P&gt;I was able to get this to work but I had to overcome a couple of problems. The main problem was indeed thread related.&lt;/P&gt;&lt;P&gt;The MapViewOverlayControl needs to be created on the main/UI thread. Furthermore the AddOverlayControl and RemoveOverlayControl methods need to be called on the same thread where the control has been created.&lt;/P&gt;&lt;P&gt;My solution is now a little heavy. I create the control when my map view is initialized.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;_courseEndOverlay = 
    new MapViewOverlayControl(new CourseEndMessageControlView(), true, true, 
        true, OverlayControlRelativePosition.Center, 0.5, 0.5);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It sends a message from inner thread to outer with delegate callback but then I'm still not exactly on the same thread as my control ... so I need&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;System.Windows.Application.Current.Dispatcher.Invoke((Action)delegate {
    _logger.Debug("show course end control");
    MapView.Active.AddOverlayControl(_courseEndOverlay);
});

await QueuedTask.Run(() =&amp;gt; {
    Task.Delay(4000).Wait();
    System.Windows.Application.Current.Dispatcher.Invoke((Action)delegate {
        MapView.Active.RemoveOverlayControl(_courseEndOverlay);
    });
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 13:43:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1092189#M7071</guid>
      <dc:creator>RichardReinicke</dc:creator>
      <dc:date>2021-08-25T13:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: MessageBox blocks UI and map window</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1092220#M7073</link>
      <description>&lt;P&gt;You can use the following code to run actions on the UI thread - it is optimized as it first determines the 'thread context' the caller is running on:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;/// &amp;lt;summary&amp;gt;
/// utility function to enable an action to run on the UI thread (if not already)
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="action"&amp;gt;the action to execute&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
internal static void RunOnUiThread(Action action)
{
    try
    {
        if (IsOnUiThread)
            action();
        else
            Application.Current.Dispatcher.BeginInvoke(action);
    }
    catch (Exception ex)
    {
        MessageBox.Show($@"Error in OpenAndActivateMap: {ex.Message}");
    }
}

/// &amp;lt;summary&amp;gt;
/// Determines whether the calling thread is the thread associated with this 
/// System.Windows.Threading.Dispatcher, the UI thread.
/// 
/// If called from a View model test it always returns true.
/// &amp;lt;/summary&amp;gt;
public static bool IsOnUiThread =&amp;gt; ArcGIS.Desktop.Framework.FrameworkApplication.TestMode || System.Windows.Application.Current.Dispatcher.CheckAccess();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can then 'invoke' your UI actions like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// simple action
RunOnUiThread(() =&amp;gt; { /* UI action functionality */ });

// action with await 
RunOnUiThread(async () =&amp;gt; { /* UI action functionality with await */ });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think in most cases you should refrain from using Dispatcher.Invoke because it's a blocking call (meaning it doesn't return to you until it has been executed), instead you should use Dispatcher.BeginInvoke which is non blocking.&lt;/P&gt;&lt;P&gt;Also there's another issue I noticed as the following code snippet with block the 'main CIM thread' for 4 seconds:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;await QueuedTask.Run(() =&amp;gt; {
    Task.Delay(4000).Wait();
    // delayed action
});&lt;/LI-CODE&gt;&lt;P&gt;So I would recommend to run a 'delay' from an asynchronous task using something like this (this is a Pro button's OnClick method):&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class TestDelay : Button
{
  protected override void OnClick()
  {
	_ = DelayTaskAsync();
	System.Diagnostics.Debug.WriteLine("OnClick done");
  }

  static async Task DelayTaskAsync()
  {
	Task delay = Task.Delay(5000);
	await delay;
	// do your delayed action here
	System.Diagnostics.Debug.WriteLine("Delayed action");
  }
}&lt;/LI-CODE&gt;&lt;P&gt;This will not block the UI nor the CIM thread.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 15:25:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1092220#M7073</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2021-08-25T15:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: MessageBox blocks UI and map window</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1092256#M7074</link>
      <description>&lt;P&gt;Very helpful&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/12882"&gt;@Wolf&lt;/a&gt;&amp;nbsp;, thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 25 Aug 2021 15:28:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/messagebox-blocks-ui-and-map-window/m-p/1092256#M7074</guid>
      <dc:creator>RichardReinicke</dc:creator>
      <dc:date>2021-08-25T15:28:08Z</dc:date>
    </item>
  </channel>
</rss>

