<?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 Cancellation Token - Awaitable functions .NET SDK in Integration, Extension &amp; APIs</title>
    <link>https://community.qlik.com/t5/Integration-Extension-APIs/Cancellation-Token-Awaitable-functions-NET-SDK/m-p/1723841#M12961</link>
    <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;How do you control the timeout of an awaitable function, lets say:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Dim fi = Await app.GetFieldAsync(field_name)
Await fi.SelectAsync(value, True)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would like to achieve is to define a cancellation token and use it to cancel the task after a timeout, catch the exception and retry the same task with a wait period in between.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Dim cts As CancellationTokenSource = New CancellationTokenSource
cts.CancelAfter(TimeSpan.FromSeconds(100))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason I am asking this is that not rarely I see the application hangs out trying to make those 2 operations. Just hangs indefinitely and never return something.&lt;/P&gt;&lt;P&gt;Is there anyway to achieve a retry policy in case of timeout with .NET SDK's await-able functions?&lt;/P&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;&lt;P&gt;Catalin&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 16 Nov 2024 02:00:35 GMT</pubDate>
    <dc:creator>catalin</dc:creator>
    <dc:date>2024-11-16T02:00:35Z</dc:date>
    <item>
      <title>Cancellation Token - Awaitable functions .NET SDK</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Cancellation-Token-Awaitable-functions-NET-SDK/m-p/1723841#M12961</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;How do you control the timeout of an awaitable function, lets say:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Dim fi = Await app.GetFieldAsync(field_name)
Await fi.SelectAsync(value, True)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would like to achieve is to define a cancellation token and use it to cancel the task after a timeout, catch the exception and retry the same task with a wait period in between.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Dim cts As CancellationTokenSource = New CancellationTokenSource
cts.CancelAfter(TimeSpan.FromSeconds(100))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason I am asking this is that not rarely I see the application hangs out trying to make those 2 operations. Just hangs indefinitely and never return something.&lt;/P&gt;&lt;P&gt;Is there anyway to achieve a retry policy in case of timeout with .NET SDK's await-able functions?&lt;/P&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;&lt;P&gt;Catalin&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 02:00:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Cancellation-Token-Awaitable-functions-NET-SDK/m-p/1723841#M12961</guid>
      <dc:creator>catalin</dc:creator>
      <dc:date>2024-11-16T02:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: Cancellation Token - Awaitable functions .NET SDK</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Cancellation-Token-Awaitable-functions-NET-SDK/m-p/1725116#M12983</link>
      <description>&lt;P&gt;There's no&amp;nbsp; built in support for this I'm afraid, but you could write a function like this (sorry for the C#, I'm not too fluent in VB):&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private static async Task&amp;lt;T&amp;gt; Cancellable&amp;lt;T&amp;gt;(Task&amp;lt;T&amp;gt; task, CancellationToken token)
{
    var cancelTask = Task.Delay(TimeSpan.MaxValue, token);
    await Task.WhenAny(task, cancelTask);
    if (cancelTask.IsCanceled)
        throw new TaskCanceledException(task);
    return await task;
}&lt;/LI-CODE&gt;&lt;P&gt;Then with that function you should be able to write your code like this:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var tcs = new CancellationTokenSource(TimeSpan.FromSeconds(100));
var token = tcs.Token;
try
{
    var fi = await Cancellable(app.GetFieldAsync(field_name), token);
    await Cancellable(fi.SelectAsync(value, true), token);
}
catch (TaskCanceledException e)
{
    Console.WriteLine("Operation was cancelled: " + e.Message);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;But it sounds strange that you should see it stall there in the first place. Is it reproduceable? Or is it non-deterministic?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 12:01:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Cancellation-Token-Awaitable-functions-NET-SDK/m-p/1725116#M12983</guid>
      <dc:creator>Øystein_Kolsrud</dc:creator>
      <dc:date>2020-07-05T12:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Cancellation Token - Awaitable functions .NET SDK</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Cancellation-Token-Awaitable-functions-NET-SDK/m-p/1725153#M12984</link>
      <description>&lt;P&gt;Exactly this degree of randomness consistent with&amp;nbsp; a non-deterministic behavior makes my hair turn white. It's a Windows service that runs a scheduled Quartz.NET job each morning.&lt;/P&gt;&lt;P&gt;This service runs under a specific domain user who is also a root admin in QS. Now, this job iterates over a list of values and apply each of the list's value as a QS selection on that specific field and exports the data behind a table object as an Excel file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I may have a clue: sometimes there's someone else, another user, who logs in with the same username as the service.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible if one opens a QS session with the same username to mess up the running job?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm speculating it would mess up the outputs of either the exported Excel file or the user's selections in the QS GUI, but it would not hang the entire execution.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyhow, I will wrap your nice suggestion for a cancel-able function with a retry policy and I will come back with a feedback.&lt;/P&gt;&lt;P&gt;Thanks a lot,&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/41242"&gt;@Øystein_Kolsrud&lt;/a&gt;!&lt;/P&gt;&lt;P&gt;Catalin&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 19:18:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Cancellation-Token-Awaitable-functions-NET-SDK/m-p/1725153#M12984</guid>
      <dc:creator>catalin</dc:creator>
      <dc:date>2020-07-05T19:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: Cancellation Token - Awaitable functions .NET SDK</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Cancellation-Token-Awaitable-functions-NET-SDK/m-p/1727001#M13004</link>
      <description>&lt;P&gt;Another user could certainly affect the results of the selection if that user connects to the same engine session as your service. You should make sure to use a unique session for the service when you connect to the engine. Something like this:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using(var hub = location.Hub(Session.Random))
{
    ...
}&lt;/LI-CODE&gt;&lt;P&gt;But depending on your connection type and proxy settings, it could be that you get disconnected if you have the same user connecting from somewhere else.&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jul 2020 08:32:42 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Cancellation-Token-Awaitable-functions-NET-SDK/m-p/1727001#M13004</guid>
      <dc:creator>Øystein_Kolsrud</dc:creator>
      <dc:date>2020-07-11T08:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Cancellation Token - Awaitable functions .NET SDK</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Cancellation-Token-Awaitable-functions-NET-SDK/m-p/1742666#M13211</link>
      <description>&lt;P&gt;So actually the Hub is the big daddy for the app object too?&lt;/P&gt;&lt;P&gt;Is this:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using (var app = location.App(appIdentifier, session: Session.Random))
{
...
}&lt;/LI-CODE&gt;&lt;P&gt;equivalent to calling the hub and then get the app? Means that this calls the hub anyway in the background, right?&lt;/P&gt;&lt;P&gt;Thanks alot!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2020 07:09:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Cancellation-Token-Awaitable-functions-NET-SDK/m-p/1742666#M13211</guid>
      <dc:creator>catalin</dc:creator>
      <dc:date>2020-09-10T07:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: Cancellation Token - Awaitable functions .NET SDK</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Cancellation-Token-Awaitable-functions-NET-SDK/m-p/1742672#M13213</link>
      <description>&lt;P&gt;Yes, that is correct. The location.App is basically just calling location.Hub followed by hub.OpenApp.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2020 07:27:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Cancellation-Token-Awaitable-functions-NET-SDK/m-p/1742672#M13213</guid>
      <dc:creator>Øystein_Kolsrud</dc:creator>
      <dc:date>2020-09-10T07:27:34Z</dc:date>
    </item>
  </channel>
</rss>

