<?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: Multithreading with ArcGIS Map running on its own thread in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/multithreading-with-arcgis-map-running-on-its-own/m-p/147495#M1670</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can't update the UI from a background thread. You'll need to use the Dispatcher to switch back to the UI Thread to update the UI:&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;textbox.Text = i.ToString();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;Dispatcher&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;BeginInvoke&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
    textbox&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Text &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; i&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;ToString&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Generally I don't recommend using new Thread(). Instead use Task.Run instead, and to sleep use 'await Task.Delay(milliseconds);' to avoid holding up the thread completely.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 08:01:06 GMT</pubDate>
    <dc:creator>dotMorten_esri</dc:creator>
    <dc:date>2021-12-11T08:01:06Z</dc:date>
    <item>
      <title>Multithreading with ArcGIS Map running on its own thread</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/multithreading-with-arcgis-map-running-on-its-own/m-p/147493#M1668</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm new to ArcGIS SDK and using C# in general so please bare with me. I'm currently creating a .Net Application in C# that will display a GPS location of a robotic-vehicle in real time while also displaying other data from the vehicle e.g. engine speed, spray pressure, vehicle speed etc. The displaying of the vehicles location within the ArcGIS esri map works great and doesn't freeze that U.I. at all. I created two different threads, each with a socket, exclusively for receiving or&amp;nbsp;sending data. The GPS position of the robotic-vehicle comes in through the&amp;nbsp;receiving&amp;nbsp;socket at ~ 20hz. However, when I send data to be displayed in an odometer that I made or even a simple &lt;SPAN&gt;text box&amp;nbsp;&lt;/SPAN&gt;then the U.I. completely freezes until the operation is complete or just shuts down.&lt;/P&gt;&lt;P&gt;I have tried to create the operation of changing the text box/odometer in it's own thread and calling Thread.Sleep() within that function, but it has the same outcome where it doesn't show the incremental changes in the display, but rather the result after the entire operation is completed or shutdown completely.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My MainWindow.xaml.cs looks something like the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;namespace ArcGISRuntime.WPF.Samples.SketchOnMap&amp;nbsp;&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;private GraphicsOverlay _sketchOverlay;&lt;/P&gt;&lt;P&gt;public SketchOnMap()&lt;BR /&gt; {&lt;BR /&gt; InitializeComponent();&lt;/P&gt;&lt;P&gt;// Call a function to set up the map and sketch editor&lt;BR /&gt; Initialize();&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;private void Initialize()&lt;BR /&gt; {&lt;BR /&gt; // Create a light gray canvas map&lt;BR /&gt; Map myMap = new Map(Basemap.CreateImageryWithLabelsVector());&lt;/P&gt;&lt;P&gt;// Create central point where map is centered&lt;BR /&gt; MapPoint centralPoint = new MapPoint(X, Y, SpatialReferences.Wgs84);&lt;/P&gt;&lt;P&gt;// Create starting viewpoint&lt;BR /&gt; Viewpoint startingViewpoint = new Viewpoint(&lt;BR /&gt; centralPoint,&lt;BR /&gt; 3000);&lt;BR /&gt; // Set starting viewpoint&lt;BR /&gt; myMap.InitialViewpoint = startingViewpoint;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; // Create graphics overlay to display sketch geometry&lt;BR /&gt; _sketchOverlay = new GraphicsOverlay();&lt;BR /&gt; MyMapView.GraphicsOverlays.Add(_sketchOverlay);&lt;/P&gt;&lt;P&gt;// Assign the map to the MapView&lt;BR /&gt; MyMapView.Map = myMap;&lt;/P&gt;&lt;P&gt;// Fill the combo box with choices for the sketch modes (shapes)&lt;BR /&gt; SketchModeComboBox.ItemsSource = System.Enum.GetValues(typeof(SketchCreationMode));&lt;BR /&gt; SketchModeComboBox.SelectedIndex = 0;&lt;/P&gt;&lt;P&gt;// Set the sketch editor as the page's data context&lt;BR /&gt; DataContext = MyMapView.SketchEditor;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;private void Update(){&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;for (int i = 0; i &amp;lt; 8000; i++){&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;textbox.Text = i.ToString();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Thread.Sleep(1000);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;private async void DrawButtonClick(object sender, RoutedEventArgs e){}....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;private void ButtonSock_Click(Object sender, RoutedEventArgs e){&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thread th1 = new Thread(Update);&lt;/P&gt;&lt;P&gt;th1.Start();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please let me know if you have any suggestions for this. To reiterate, I can continually display the robotic-vehicles location without freezing since I have a method within the same public partial class SketchOnMap that uses the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;private void Draw_Position(byte[] b_lat, byte[] b_lon){&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;double d_lat = ConvertByteArrayToDouble(b_lat);&lt;BR /&gt; double d_lon = ConvertByteArrayToDouble(b_lon);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; MapPoint startingPoint = new MapPoint(d_lon, d_lat, SpatialReferences.Wgs84);&lt;/P&gt;&lt;P&gt;// Create a symbol to symbolize the point&lt;BR /&gt; SimpleMarkerSymbol symbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Black, 10);&lt;/P&gt;&lt;P&gt;// Create the graphic&lt;BR /&gt; Graphic symbolGraphic = new Graphic(startingPoint, symbol);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; _sketchOverlay.Graphics.Add(symbolGraphic);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Aug 2020 21:38:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/multithreading-with-arcgis-map-running-on-its-own/m-p/147493#M1668</guid>
      <dc:creator>DanSepeda</dc:creator>
      <dc:date>2020-08-26T21:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Multithreading with ArcGIS Map running on its own thread</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/multithreading-with-arcgis-map-running-on-its-own/m-p/147494#M1669</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The issue is most likely caused by the synchronous coding pattern you've used with void methods and blocking Thread.Sleep calls. Instead I recommend taking a look at some articles on asynchronous programming e.g.&amp;nbsp;&lt;A class="link-titled" href="https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/" title="https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/"&gt;Asynchronous programming in C# | Microsoft Docs&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Aug 2020 12:48:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/multithreading-with-arcgis-map-running-on-its-own/m-p/147494#M1669</guid>
      <dc:creator>MichaelBranscomb</dc:creator>
      <dc:date>2020-08-27T12:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: Multithreading with ArcGIS Map running on its own thread</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/multithreading-with-arcgis-map-running-on-its-own/m-p/147495#M1670</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can't update the UI from a background thread. You'll need to use the Dispatcher to switch back to the UI Thread to update the UI:&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;textbox.Text = i.ToString();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;Dispatcher&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;BeginInvoke&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
    textbox&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Text &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; i&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;ToString&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Generally I don't recommend using new Thread(). Instead use Task.Run instead, and to sleep use 'await Task.Delay(milliseconds);' to avoid holding up the thread completely.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:01:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/multithreading-with-arcgis-map-running-on-its-own/m-p/147495#M1670</guid>
      <dc:creator>dotMorten_esri</dc:creator>
      <dc:date>2021-12-11T08:01:06Z</dc:date>
    </item>
    <item>
      <title>Re: Multithreading with ArcGIS Map running on its own thread</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/multithreading-with-arcgis-map-running-on-its-own/m-p/147496#M1671</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Morten, Thanks for your help. You are spot. I wasn't able to update the UI from background thread so instead I used exactly what you said. I created a delegate object and then called the Dispatcher to switch back to the UI which worked perfectly.&amp;nbsp; Thanks again for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Aug 2020 20:20:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/multithreading-with-arcgis-map-running-on-its-own/m-p/147496#M1671</guid>
      <dc:creator>DanSepeda</dc:creator>
      <dc:date>2020-08-27T20:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Multithreading with ArcGIS Map running on its own thread</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/multithreading-with-arcgis-map-running-on-its-own/m-p/147497#M1672</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Michael, thanks for the article I'll take a look through it. As Morten, suggested I needed to create a Dispatcher to switch back to the UI thread- which worked great. I definitely need to read more up on multi threading. Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Aug 2020 20:24:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/multithreading-with-arcgis-map-running-on-its-own/m-p/147497#M1672</guid>
      <dc:creator>DanSepeda</dc:creator>
      <dc:date>2020-08-27T20:24:36Z</dc:date>
    </item>
  </channel>
</rss>

