<?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 AsyncPresentationEvent: how to know what Task to return? in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/asyncpresentationevent-how-to-know-what-task-to/m-p/1019308#M6055</link>
    <description>&lt;P&gt;Hi -&lt;/P&gt;&lt;P&gt;How do I figure out what to return in a Task when handling an&amp;nbsp;AsyncPresentationEvent?&lt;/P&gt;&lt;P&gt;For example&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/#topic9762.html" target="_self"&gt; this sample&lt;/A&gt; shows Task.FromResult(0) being returned, how was this (0) determined?&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected void subEditEvents()
{
  //subscribe to editcompleted
  var eceToken = EditCompletedEvent.Subscribe(onEce);
}

protected Task onEce(EditCompletedEventArgs args)
{
  //show number of edits
  Console.WriteLine("Creates: " + args.Creates.Values.Sum(list =&amp;gt; list.Count).ToString());
  Console.WriteLine("Modifies: " + args.Modifies.Values.Sum(list =&amp;gt; list.Count).ToString());
  Console.WriteLine("Deletes: " + args.Deletes.Values.Sum(list =&amp;gt; list.Count).ToString());
  return Task.FromResult(0);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks, Kirk&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Jan 2021 22:33:38 GMT</pubDate>
    <dc:creator>KirkKuykendall1</dc:creator>
    <dc:date>2021-01-22T22:33:38Z</dc:date>
    <item>
      <title>AsyncPresentationEvent: how to know what Task to return?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/asyncpresentationevent-how-to-know-what-task-to/m-p/1019308#M6055</link>
      <description>&lt;P&gt;Hi -&lt;/P&gt;&lt;P&gt;How do I figure out what to return in a Task when handling an&amp;nbsp;AsyncPresentationEvent?&lt;/P&gt;&lt;P&gt;For example&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/#topic9762.html" target="_self"&gt; this sample&lt;/A&gt; shows Task.FromResult(0) being returned, how was this (0) determined?&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected void subEditEvents()
{
  //subscribe to editcompleted
  var eceToken = EditCompletedEvent.Subscribe(onEce);
}

protected Task onEce(EditCompletedEventArgs args)
{
  //show number of edits
  Console.WriteLine("Creates: " + args.Creates.Values.Sum(list =&amp;gt; list.Count).ToString());
  Console.WriteLine("Modifies: " + args.Modifies.Values.Sum(list =&amp;gt; list.Count).ToString());
  Console.WriteLine("Deletes: " + args.Deletes.Values.Sum(list =&amp;gt; list.Count).ToString());
  return Task.FromResult(0);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks, Kirk&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 22:33:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/asyncpresentationevent-how-to-know-what-task-to/m-p/1019308#M6055</guid>
      <dc:creator>KirkKuykendall1</dc:creator>
      <dc:date>2021-01-22T22:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: AsyncPresentationEvent: how to know what Task to return?</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/asyncpresentationevent-how-to-know-what-task-to/m-p/1020630#M6087</link>
      <description>&lt;P&gt;If you hover over the&amp;nbsp;EditCompletedEvent.Subscribe method in Visual Studio (or use the Pro SDK API reference) you find the following parameters for the Subscribe method:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public static SubscriptionToken Subscribe( 
   Func&amp;lt;EditCompletedEventArgs,Task&amp;gt; action,
   bool keepSubscriberAlive
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;This shows that the first parameter is a &lt;A href="https://docs.microsoft.com/en-us/dotnet/api/system.func-2?view=net-5.0" target="_self"&gt;delegate function&lt;/A&gt; that has an input parameter of the type 'EditCompletedEventArgs' and returns a class of the type&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task?view=net-5.0" target="_self"&gt;System.Threading.Tasks.Task&lt;/A&gt;&amp;nbsp; .&amp;nbsp; The Task class is derived from the &lt;A href="https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1?view=net-5.0" target="_self"&gt;'Task &amp;lt;TResult&amp;gt; class'&lt;/A&gt;&amp;nbsp;.&amp;nbsp; Both variations of the Task class&amp;nbsp;represent a single operation that usually executes asynchronously, however, whereas 'Task&amp;lt;TResult&amp;gt;' returns a value (of the type TResult), 'Task' doesn't return a value.&amp;nbsp; Consequently your delegate above 'onEce' has to return an instance of the Task class and the way to do this is to use the '&lt;A href="https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.fromresult?view=net-5.0" target="_self"&gt;Task.FromResult&amp;lt;TResult&amp;gt;(TResult)&lt;/A&gt;' method and since TResult is not required you can specify either null or 0 as the parameter.&amp;nbsp; FromResult returns an instance of the task class that you need as your return parameter.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2021 19:41:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/asyncpresentationevent-how-to-know-what-task-to/m-p/1020630#M6087</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2021-01-27T19:41:53Z</dc:date>
    </item>
  </channel>
</rss>

