<?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: Using Geometry service using TPL in ArcGIS API for Silverlight Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/using-geometry-service-using-tpl/m-p/673027#M17300</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt; Task.WaitAll(task1);&lt;/PRE&gt;&lt;BR /&gt;When the code reaches "&lt;SPAN style="font-style:italic;"&gt;Task.WaitAll(task1);&lt;/SPAN&gt;" line, I wait for ever;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your call to WaitAll is blocking the UIThread and as SimplifyAsync is an asynchronous method which needs the UIThread, you are stuck.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It's exactly what the new C# 'await' operator is done for : i.e. to use asynchonous task without blocking the thread.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That being said, .Net Framework 4.0 and SL5 doesn't support the 'await' operator except if you download and install the &lt;/SPAN&gt;&lt;A href="http://www.microsoft.com/en-us/download/details.aspx?id=29576" rel="nofollow noopener noreferrer" target="_blank"&gt;Async Targetting Pack&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Without this pack, you can get the same behavior by using the ContinueWith method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Task&amp;lt;IList&amp;lt;Graphic&amp;gt;&amp;gt; task1 = geometryService.SimplifyTask(PstLayer.Graphics);
task1.ContinueWith(t =&amp;gt;
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; IList&amp;lt;Graphic&amp;gt; simplifiedPstLayer = t.Result;

&amp;nbsp;&amp;nbsp;&amp;nbsp; // add here your code using the simplified graphics

}, TaskScheduler.FromCurrentSynchronizationContext()); 


// No more code here
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Obviously the syntaxic sugar of the await operator gets lost.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note : another option would be to execute your task in another thread, but in this particular case it's not working since the graphics need to be created in the UIThread and so SymplifyAsync can only be executed in the UI Thread.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 04:24:22 GMT</pubDate>
    <dc:creator>DominiqueBroux</dc:creator>
    <dc:date>2021-12-12T04:24:22Z</dc:date>
    <item>
      <title>Using Geometry service using TPL</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/using-geometry-service-using-tpl/m-p/673026#M17299</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to implement a sequence of calls to Geometry service. I want to implements these calls as Tasks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have the following extension method,&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;public static Task&amp;lt;IList&amp;lt;Graphic&amp;gt;&amp;gt; SimplifyTask(this GeometryService gc, IList&amp;lt;Graphic&amp;gt; graphics)
{
 TaskCompletionSource&amp;lt;IList&amp;lt;Graphic&amp;gt;&amp;gt; tcs = new TaskCompletionSource&amp;lt;IList&amp;lt;Graphic&amp;gt;&amp;gt;();
 EventHandler&amp;lt;GraphicsEventArgs&amp;gt; SimplifyCompleted = delegate { };
 EventHandler&amp;lt;TaskFailedEventArgs&amp;gt; Failed = delegate { };
 SimplifyCompleted = (sender, e) =&amp;gt;
 {
&amp;nbsp; gc.SimplifyCompleted -= SimplifyCompleted;
&amp;nbsp; gc.Failed -= Failed;
&amp;nbsp; tcs.TrySetResult(e.Results);
 };
 Failed = (sender, e) =&amp;gt;
 {
&amp;nbsp; gc.SimplifyCompleted -= SimplifyCompleted;
&amp;nbsp; gc.Failed -= Failed;
&amp;nbsp; tcs.TrySetException(e.Error);
 };
 try
 {
&amp;nbsp; gc.SimplifyCompleted += SimplifyCompleted;
&amp;nbsp; gc.Failed += Failed;
&amp;nbsp; gc.SimplifyAsync(graphics);
 }
 catch (Exception ex)
 {
&amp;nbsp; tcs.TrySetException(ex);
&amp;nbsp; gc.SimplifyCompleted -= SimplifyCompleted;
&amp;nbsp; gc.Failed -= Failed;
 }
 return tcs.Task;
}&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;that I am trying to use through this code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
 geometryService = new GeometryService("&lt;A href="http://arcgis/ArcGIS/rest/services/Geometry/GeometryServer" rel="nofollow noopener noreferrer" target="_blank"&gt;http://arcgis/ArcGIS/rest/services/Geometry/GeometryServer&lt;/A&gt;");
 Task&amp;lt;IList&amp;lt;Graphic&amp;gt;&amp;gt; task1 = geometryService.SimplifyTask(PstLayer.Graphics);
 Task.WaitAll(task1);
 IList&amp;lt;Graphic&amp;gt; simplifiedPstLayer = task1.Result;
&lt;/PRE&gt;&lt;SPAN&gt;When the code reaches "&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Task.WaitAll(task1);&lt;/SPAN&gt;&lt;SPAN&gt;" line, I wait for ever; Having breakpoints inside SimplifyCompleted and Failed handlers, the execution never reaches this point...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there any help, pointers somebody has to offer?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;George J.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:24:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/using-geometry-service-using-tpl/m-p/673026#M17299</guid>
      <dc:creator>George_J_Capnias</dc:creator>
      <dc:date>2021-12-12T04:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using Geometry service using TPL</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/using-geometry-service-using-tpl/m-p/673027#M17300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt; Task.WaitAll(task1);&lt;/PRE&gt;&lt;BR /&gt;When the code reaches "&lt;SPAN style="font-style:italic;"&gt;Task.WaitAll(task1);&lt;/SPAN&gt;" line, I wait for ever;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your call to WaitAll is blocking the UIThread and as SimplifyAsync is an asynchronous method which needs the UIThread, you are stuck.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It's exactly what the new C# 'await' operator is done for : i.e. to use asynchonous task without blocking the thread.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That being said, .Net Framework 4.0 and SL5 doesn't support the 'await' operator except if you download and install the &lt;/SPAN&gt;&lt;A href="http://www.microsoft.com/en-us/download/details.aspx?id=29576" rel="nofollow noopener noreferrer" target="_blank"&gt;Async Targetting Pack&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Without this pack, you can get the same behavior by using the ContinueWith method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Task&amp;lt;IList&amp;lt;Graphic&amp;gt;&amp;gt; task1 = geometryService.SimplifyTask(PstLayer.Graphics);
task1.ContinueWith(t =&amp;gt;
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; IList&amp;lt;Graphic&amp;gt; simplifiedPstLayer = t.Result;

&amp;nbsp;&amp;nbsp;&amp;nbsp; // add here your code using the simplified graphics

}, TaskScheduler.FromCurrentSynchronizationContext()); 


// No more code here
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Obviously the syntaxic sugar of the await operator gets lost.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note : another option would be to execute your task in another thread, but in this particular case it's not working since the graphics need to be created in the UIThread and so SymplifyAsync can only be executed in the UI Thread.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:24:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/using-geometry-service-using-tpl/m-p/673027#M17300</guid>
      <dc:creator>DominiqueBroux</dc:creator>
      <dc:date>2021-12-12T04:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using Geometry service using TPL</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/using-geometry-service-using-tpl/m-p/673028#M17301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Better late than never.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is an extension for SL API that can help you with async/await:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="https://arcgisasync.codeplex.com/"&gt;https://arcgisasync.codeplex.com/&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Sep 2013 15:42:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/using-geometry-service-using-tpl/m-p/673028#M17301</guid>
      <dc:creator>DenisT</dc:creator>
      <dc:date>2013-09-06T15:42:57Z</dc:date>
    </item>
  </channel>
</rss>

