<?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 MultiThreading / Parallel Processing in ArcGIS Pro AddIn in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/multithreading-parallel-processing-in-arcgis-pro/m-p/809540#M2305</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am working on an ArcGIS 2.4.1 Pro AddIn that processes CPU-intensive tasks. One of the tasks is to create Polygons from parts of different PolyLines, which I achieved with the following code (shortened to the minimal relevant part):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2b91af;"&gt;PolylineBuilder&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="color: #1f377f;"&gt;polylineBuilder&lt;/SPAN&gt;&amp;nbsp;=&amp;nbsp;&lt;SPAN style="color: blue;"&gt;new&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="color: #2b91af;"&gt;PolylineBuilder&lt;/SPAN&gt;(SpatialReference);&lt;BR /&gt;&lt;SPAN style="color: #1f377f;"&gt;polylineBuilder&lt;/SPAN&gt;.AddParts(contourPolyLine.Parts);&lt;BR /&gt;&lt;SPAN style="color: #1f377f;"&gt;polylineBuilder&lt;/SPAN&gt;.SplitAtDistance(splitDistance,&amp;nbsp;&lt;SPAN style="color: blue;"&gt;false&lt;/SPAN&gt;,&amp;nbsp;&lt;SPAN style="color: blue;"&gt;true&lt;/SPAN&gt;);&lt;BR /&gt;&lt;SPAN style="color: blue;"&gt;var&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="color: #1f377f;"&gt;newPolygon3D&lt;/SPAN&gt;&amp;nbsp;=&amp;nbsp;&lt;SPAN style="color: #2b91af;"&gt;PolygonBuilder&lt;/SPAN&gt;.&lt;SPAN style="color: #74531f;"&gt;CreatePolygon&lt;/SPAN&gt;(&lt;SPAN style="color: #1f377f;"&gt;polylineBuilder&lt;/SPAN&gt;.&lt;SPAN style="color: #74531f;"&gt;ToGeometry&lt;/SPAN&gt;()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&lt;SPAN style="color: #74531f;"&gt;Copy3DCoordinatesToList&lt;/SPAN&gt;(),&amp;nbsp;SpatialReference);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works just fine by itself, but took 40 minutes to process for about 3.000 objects. As this is run within &lt;SPAN style="color: #2b91af;"&gt;QueuedTask&lt;/SPAN&gt;.&lt;SPAN style="color: #74531f;"&gt;Run&lt;/SPAN&gt;(&lt;SPAN style="color: blue;"&gt;async&lt;/SPAN&gt;&amp;nbsp;()&amp;nbsp;=&amp;gt;...), ArcGIS Pro only utilized 1 CPU core of my 8 core machine. All attempts of separating the work and running several parallel tasks failed so far, because&amp;nbsp;&lt;SPAN style="color: #2b91af;"&gt;PolylineBuilder&lt;/SPAN&gt;&amp;nbsp;can not be used in a regular Task.Run(...)-Thread (Exception is thrown: "This object must be created within the lambda passed to QueuedTask.Run, or on a compatible STA thread.").&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had a look at&amp;nbsp;&lt;A class="link-titled" href="https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Framework#working-with-multithreading-in-arcgis-pro" title="https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Framework#working-with-multithreading-in-arcgis-pro"&gt;ProConcepts Framework · Esri/arcgis-pro-sdk Wiki · GitHub&lt;/A&gt;&amp;nbsp;&amp;nbsp;and searched the community samples but couldn't find a similar scenario.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In another ArcGIS AddIn&amp;nbsp;I was able to use 100% of the CPU by creating multiple threads that each take a part of the workload, but in that case I had only calculations with regular managed code and no ArcGIS Pro Tools were involved:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: blue;"&gt;await&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="color: #2b91af;"&gt;Task&lt;/SPAN&gt;.&lt;SPAN style="color: #74531f;"&gt;WhenAll&lt;/SPAN&gt;(&lt;SPAN style="color: #2b91af;"&gt;Enumerable&lt;/SPAN&gt;.&lt;SPAN style="color: #74531f;"&gt;Range&lt;/SPAN&gt;(1,&amp;nbsp;&lt;SPAN style="color: #2b91af;"&gt;Environment&lt;/SPAN&gt;.ProcessorCount).&lt;SPAN style="color: #74531f;"&gt;Select&lt;/SPAN&gt;(&lt;SPAN style="color: #1f377f;"&gt;c&lt;/SPAN&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;SPAN style="color: #2b91af;"&gt;Task&lt;/SPAN&gt;.&lt;SPAN style="color: #74531f;"&gt;Run&lt;/SPAN&gt;( ()&amp;nbsp;=&amp;gt;&amp;nbsp;{&amp;nbsp;&lt;SPAN style="color: #74531f;"&gt;DoWork&lt;/SPAN&gt;(); }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a solution to utilize the full CPU also for jobs that use&amp;nbsp;ArcGIS.Core.Geometry Tools/Classes like &lt;SPAN style="color: #2b91af;"&gt;PolylineBuilder&lt;/SPAN&gt;?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any hint or example would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 04 Nov 2019 16:14:06 GMT</pubDate>
    <dc:creator>GovindaGross</dc:creator>
    <dc:date>2019-11-04T16:14:06Z</dc:date>
    <item>
      <title>MultiThreading / Parallel Processing in ArcGIS Pro AddIn</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/multithreading-parallel-processing-in-arcgis-pro/m-p/809540#M2305</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am working on an ArcGIS 2.4.1 Pro AddIn that processes CPU-intensive tasks. One of the tasks is to create Polygons from parts of different PolyLines, which I achieved with the following code (shortened to the minimal relevant part):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2b91af;"&gt;PolylineBuilder&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="color: #1f377f;"&gt;polylineBuilder&lt;/SPAN&gt;&amp;nbsp;=&amp;nbsp;&lt;SPAN style="color: blue;"&gt;new&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="color: #2b91af;"&gt;PolylineBuilder&lt;/SPAN&gt;(SpatialReference);&lt;BR /&gt;&lt;SPAN style="color: #1f377f;"&gt;polylineBuilder&lt;/SPAN&gt;.AddParts(contourPolyLine.Parts);&lt;BR /&gt;&lt;SPAN style="color: #1f377f;"&gt;polylineBuilder&lt;/SPAN&gt;.SplitAtDistance(splitDistance,&amp;nbsp;&lt;SPAN style="color: blue;"&gt;false&lt;/SPAN&gt;,&amp;nbsp;&lt;SPAN style="color: blue;"&gt;true&lt;/SPAN&gt;);&lt;BR /&gt;&lt;SPAN style="color: blue;"&gt;var&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="color: #1f377f;"&gt;newPolygon3D&lt;/SPAN&gt;&amp;nbsp;=&amp;nbsp;&lt;SPAN style="color: #2b91af;"&gt;PolygonBuilder&lt;/SPAN&gt;.&lt;SPAN style="color: #74531f;"&gt;CreatePolygon&lt;/SPAN&gt;(&lt;SPAN style="color: #1f377f;"&gt;polylineBuilder&lt;/SPAN&gt;.&lt;SPAN style="color: #74531f;"&gt;ToGeometry&lt;/SPAN&gt;()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&lt;SPAN style="color: #74531f;"&gt;Copy3DCoordinatesToList&lt;/SPAN&gt;(),&amp;nbsp;SpatialReference);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This works just fine by itself, but took 40 minutes to process for about 3.000 objects. As this is run within &lt;SPAN style="color: #2b91af;"&gt;QueuedTask&lt;/SPAN&gt;.&lt;SPAN style="color: #74531f;"&gt;Run&lt;/SPAN&gt;(&lt;SPAN style="color: blue;"&gt;async&lt;/SPAN&gt;&amp;nbsp;()&amp;nbsp;=&amp;gt;...), ArcGIS Pro only utilized 1 CPU core of my 8 core machine. All attempts of separating the work and running several parallel tasks failed so far, because&amp;nbsp;&lt;SPAN style="color: #2b91af;"&gt;PolylineBuilder&lt;/SPAN&gt;&amp;nbsp;can not be used in a regular Task.Run(...)-Thread (Exception is thrown: "This object must be created within the lambda passed to QueuedTask.Run, or on a compatible STA thread.").&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had a look at&amp;nbsp;&lt;A class="link-titled" href="https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Framework#working-with-multithreading-in-arcgis-pro" title="https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Framework#working-with-multithreading-in-arcgis-pro"&gt;ProConcepts Framework · Esri/arcgis-pro-sdk Wiki · GitHub&lt;/A&gt;&amp;nbsp;&amp;nbsp;and searched the community samples but couldn't find a similar scenario.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In another ArcGIS AddIn&amp;nbsp;I was able to use 100% of the CPU by creating multiple threads that each take a part of the workload, but in that case I had only calculations with regular managed code and no ArcGIS Pro Tools were involved:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: blue;"&gt;await&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN style="color: #2b91af;"&gt;Task&lt;/SPAN&gt;.&lt;SPAN style="color: #74531f;"&gt;WhenAll&lt;/SPAN&gt;(&lt;SPAN style="color: #2b91af;"&gt;Enumerable&lt;/SPAN&gt;.&lt;SPAN style="color: #74531f;"&gt;Range&lt;/SPAN&gt;(1,&amp;nbsp;&lt;SPAN style="color: #2b91af;"&gt;Environment&lt;/SPAN&gt;.ProcessorCount).&lt;SPAN style="color: #74531f;"&gt;Select&lt;/SPAN&gt;(&lt;SPAN style="color: #1f377f;"&gt;c&lt;/SPAN&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;SPAN style="color: #2b91af;"&gt;Task&lt;/SPAN&gt;.&lt;SPAN style="color: #74531f;"&gt;Run&lt;/SPAN&gt;( ()&amp;nbsp;=&amp;gt;&amp;nbsp;{&amp;nbsp;&lt;SPAN style="color: #74531f;"&gt;DoWork&lt;/SPAN&gt;(); }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a solution to utilize the full CPU also for jobs that use&amp;nbsp;ArcGIS.Core.Geometry Tools/Classes like &lt;SPAN style="color: #2b91af;"&gt;PolylineBuilder&lt;/SPAN&gt;?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any hint or example would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Nov 2019 16:14:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/multithreading-parallel-processing-in-arcgis-pro/m-p/809540#M2305</guid>
      <dc:creator>GovindaGross</dc:creator>
      <dc:date>2019-11-04T16:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: MultiThreading / Parallel Processing in ArcGIS Pro AddIn</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/multithreading-parallel-processing-in-arcgis-pro/m-p/809541#M2306</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To use the STA thread, you can use the&amp;nbsp;StartSTATask method in the attached TaskUtils.cs file. Here is the usage for the method:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;await&lt;/SPAN&gt; TaskUtils&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;StartSTATask&lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;int&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;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="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;
                        &lt;SPAN class="comment token"&gt;//Do Polygonbuilder task here.&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;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:28:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/multithreading-parallel-processing-in-arcgis-pro/m-p/809541#M2306</guid>
      <dc:creator>UmaHarano</dc:creator>
      <dc:date>2021-12-12T09:28:56Z</dc:date>
    </item>
  </channel>
</rss>

