<?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 QueuedTask.Run(...).Wait() hangs and await QueuedTask.Run(...) makes QueuedTask busy for too long in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/queuedtask-run-wait-hangs-and-await-queuedtask-run/m-p/1376370#M11047</link>
    <description>&lt;P&gt;&lt;SPAN&gt;QueuedTask.Run(..) hangs when I use Wait() method&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; public void SetFeatureLayerSymbolAsync(ArcGIS.Desktop.Mapping.FeatureLayer ftrLayer, CIMSymbol symbolToApply)
 {
     if (ftrLayer == null || symbolToApply == null)
         throw new System.ArgumentNullException();
     CIMSimpleRenderer currentRenderer = QueuedTask.Run(()=&amp;gt; ftrLayer.GetRenderer() as CIMSimpleRenderer).Result;
     if (currentRenderer == null)
         return;
     symbolToApply.SetRealWorldUnits(ftrLayer.UsesRealWorldSymbolSizes);
     currentRenderer.Symbol = symbolToApply.MakeSymbolReference();
     QueuedTask.Run(()=&amp;gt; ftrLayer.SetRenderer(currentRenderer)).Wait();
 }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And If I use await, it doesn't go to the next line(line 18), returns to the caller method(line 3) and QueuedTask still remains busy(line 4)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; public void SetCustomPictureSymbol(ArcGIS.Desktop.Mapping.FeatureLayer featureLayer)
 {
     SetFeatureLayerSymbolAsync(featureLayer, _symbol.Symbol);
     if (QueuedTask.Busy)
         Task.Delay(1000);
 }

 public async Task SetFeatureLayerSymbolAsync(ArcGIS.Desktop.Mapping.FeatureLayer ftrLayer, CIMSymbol symbolToApply)
 {
     if (ftrLayer == null || symbolToApply == null)
         throw new System.ArgumentNullException();
     CIMSimpleRenderer currentRenderer = QueuedTask.Run(()=&amp;gt; ftrLayer.GetRenderer() as CIMSimpleRenderer).Result;
     if (currentRenderer == null)
         return;
     symbolToApply.SetRealWorldUnits(ftrLayer.UsesRealWorldSymbolSizes);
     currentRenderer.Symbol = symbolToApply.MakeSymbolReference();
     await QueuedTask.Run(()=&amp;gt; ftrLayer.SetRenderer(currentRenderer));
     if (QueuedTask.Busy)
     {
         Task.Delay(1000);
     }
 }&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, 31 Jan 2024 11:10:52 GMT</pubDate>
    <dc:creator>Shahadat_1200</dc:creator>
    <dc:date>2024-01-31T11:10:52Z</dc:date>
    <item>
      <title>QueuedTask.Run(...).Wait() hangs and await QueuedTask.Run(...) makes QueuedTask busy for too long</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/queuedtask-run-wait-hangs-and-await-queuedtask-run/m-p/1376370#M11047</link>
      <description>&lt;P&gt;&lt;SPAN&gt;QueuedTask.Run(..) hangs when I use Wait() method&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; public void SetFeatureLayerSymbolAsync(ArcGIS.Desktop.Mapping.FeatureLayer ftrLayer, CIMSymbol symbolToApply)
 {
     if (ftrLayer == null || symbolToApply == null)
         throw new System.ArgumentNullException();
     CIMSimpleRenderer currentRenderer = QueuedTask.Run(()=&amp;gt; ftrLayer.GetRenderer() as CIMSimpleRenderer).Result;
     if (currentRenderer == null)
         return;
     symbolToApply.SetRealWorldUnits(ftrLayer.UsesRealWorldSymbolSizes);
     currentRenderer.Symbol = symbolToApply.MakeSymbolReference();
     QueuedTask.Run(()=&amp;gt; ftrLayer.SetRenderer(currentRenderer)).Wait();
 }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And If I use await, it doesn't go to the next line(line 18), returns to the caller method(line 3) and QueuedTask still remains busy(line 4)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; public void SetCustomPictureSymbol(ArcGIS.Desktop.Mapping.FeatureLayer featureLayer)
 {
     SetFeatureLayerSymbolAsync(featureLayer, _symbol.Symbol);
     if (QueuedTask.Busy)
         Task.Delay(1000);
 }

 public async Task SetFeatureLayerSymbolAsync(ArcGIS.Desktop.Mapping.FeatureLayer ftrLayer, CIMSymbol symbolToApply)
 {
     if (ftrLayer == null || symbolToApply == null)
         throw new System.ArgumentNullException();
     CIMSimpleRenderer currentRenderer = QueuedTask.Run(()=&amp;gt; ftrLayer.GetRenderer() as CIMSimpleRenderer).Result;
     if (currentRenderer == null)
         return;
     symbolToApply.SetRealWorldUnits(ftrLayer.UsesRealWorldSymbolSizes);
     currentRenderer.Symbol = symbolToApply.MakeSymbolReference();
     await QueuedTask.Run(()=&amp;gt; ftrLayer.SetRenderer(currentRenderer));
     if (QueuedTask.Busy)
     {
         Task.Delay(1000);
     }
 }&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, 31 Jan 2024 11:10:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/queuedtask-run-wait-hangs-and-await-queuedtask-run/m-p/1376370#M11047</guid>
      <dc:creator>Shahadat_1200</dc:creator>
      <dc:date>2024-01-31T11:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: QueuedTask.Run(...).Wait() hangs and await QueuedTask.Run(...) makes QueuedTask busy for too long</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/queuedtask-run-wait-hangs-and-await-queuedtask-run/m-p/1376438#M11050</link>
      <description>&lt;P&gt;Why are you applying the Wait method? Your code is almost the same as in the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic26947.html" target="_self"&gt;documentation&lt;/A&gt;, but it wraps everything in the QueuedTask and doesn't include the Wait method.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public Task SetFeatureLayerSymbolAsync(FeatureLayer ftrLayer, CIMSymbol symbolToApply)
{
  if (ftrLayer == null || symbolToApply == null)
    throw new System.ArgumentNullException();

  return QueuedTask.Run(() =&amp;gt;
  {

    //Get simple renderer from the feature layer
    CIMSimpleRenderer currentRenderer = ftrLayer.GetRenderer() as CIMSimpleRenderer;
    if (currentRenderer == null)
      return;

    //Set symbol's real world setting to be the same as that of the feature layer
    symbolToApply.SetRealWorldUnits(ftrLayer.UsesRealWorldSymbolSizes);

    //Update the symbol of the current simple renderer
    currentRenderer.Symbol = symbolToApply.MakeSymbolReference();
    //Update the feature layer renderer
    ftrLayer.SetRenderer(currentRenderer);
  });
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 14:21:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/queuedtask-run-wait-hangs-and-await-queuedtask-run/m-p/1376438#M11050</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2024-01-31T14:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: QueuedTask.Run(...).Wait() hangs and await QueuedTask.Run(...) makes QueuedTask busy for too long</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/queuedtask-run-wait-hangs-and-await-queuedtask-run/m-p/1378078#M11055</link>
      <description>&lt;P&gt;Thank you for your Reply&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/2839"&gt;@KenBuja&lt;/a&gt;&amp;nbsp; !&lt;BR /&gt;&lt;BR /&gt;We want to do it for multiple layers. For single layer it works this way but for multiple it doesn't. For the second layer it gets QueuedTask busy when we try to Run it. To fix this we were trying Wait, await and other ways.&lt;/P&gt;&lt;P&gt;It fails in all cases.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 09:25:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/queuedtask-run-wait-hangs-and-await-queuedtask-run/m-p/1378078#M11055</guid>
      <dc:creator>Shahadat_1200</dc:creator>
      <dc:date>2024-02-05T09:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: QueuedTask.Run(...).Wait() hangs and await QueuedTask.Run(...) makes QueuedTask busy for too long</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/queuedtask-run-wait-hangs-and-await-queuedtask-run/m-p/1415415#M11434</link>
      <description>&lt;P&gt;Instead of using smaller QueuedTask calls everywhere, I've found that it's better to wrap the calls in a QueuedTask so everything executes in the same task. That would also allow you to remove the Async from SetFeatureLayerSymbol Something like:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public async Task ApplySymbologyAsync()
{
  IEnumerable&amp;lt;FeatureLayer&amp;gt; featureLayers = ActiveMap.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;();
  await QueuedTask.Run(() =&amp;gt;
  {
    foreach (FeatureLayer featureLayer in featureLayers)
    {
      SetFeatureLayerSymbol(featureLayer, {howeverYouObtainYourSymbol});
    }
  });
}

public void SetFeatureLayerSymbolAsync(ArcGIS.Desktop.Mapping.FeatureLayer ftrLayer, CIMSymbol symbolToApply)
{
  if (ftrLayer == null || symbolToApply == null)
    throw new System.ArgumentNullException();
  CIMSimpleRenderer currentRenderer = ftrLayer.GetRenderer() as CIMSimpleRenderer;
  if (currentRenderer == null)
    return;
  symbolToApply.SetRealWorldUnits(ftrLayer.UsesRealWorldSymbolSizes);
  currentRenderer.Symbol = symbolToApply.MakeSymbolReference();
  ftrLayer.SetRenderer(currentRenderer);
 }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 16:43:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/queuedtask-run-wait-hangs-and-await-queuedtask-run/m-p/1415415#M11434</guid>
      <dc:creator>tempStephenRhea_NV5</dc:creator>
      <dc:date>2024-04-25T16:43:29Z</dc:date>
    </item>
  </channel>
</rss>

