<?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: Can you chain Idling events? in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11497193#M16271</link>
    <description>&lt;P&gt;Oh maybe I need to learn more about how async works in C# if its different than JS development.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would expect that if run func1 and func2 without the await flag, func2 will start before func1 has completed and the external event will be raised before func1 and func2 are completed. This would not work for my code since I would be trying to run code before the authentication step (func1) is completed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have I misunderstood? Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 20 Oct 2022 18:33:55 GMT</pubDate>
    <dc:creator>ariWZRFQ</dc:creator>
    <dc:date>2022-10-20T18:33:55Z</dc:date>
    <item>
      <title>Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11484370#M16259</link>
      <description>&lt;P&gt;Is it possible to chain Idling events?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Say I have two functions, FuncA and FuncB. I want to run FuncA the first time revit idles, then run FuncB after FuncA is done running and revit idles again. Inside my FuncA handler, I am removing the handler to FuncA from UIApp.Idling, but I can not assign a new handler because I don't have a valid API context.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way for me to achieve my intended behavior?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: The reason I'm doing any of this at all is because of &lt;A href="https://forums.autodesk.com/t5/revit-api-forum/internal-exception-downloading-file-from-server-and-the-opening/m-p/11388140#M65611" target="_blank" rel="noopener"&gt;this referenced post&lt;/A&gt;. For some reason, Revit throws an internal exception if my FuncA and FuncB are called one after the other. So I am separating them with an idling event. Now I need to add another idling event before FuncA.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Oct 2022 04:41:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11484370#M16259</guid>
      <dc:creator>ariWZRFQ</dc:creator>
      <dc:date>2022-10-15T04:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11486699#M16260</link>
      <description>&lt;P&gt;It doesn't sound like a good idea in general, however.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When Revit idles you want to run FunctionA when it idles again you want to run FunctionA but with different settings i.e. subscribe to FunctionA and change what FunctionA does based on what it did last. Then after a set number of things that FunctionA does unsubscribe. In the end you are waiting for the same event in-between doing tasks with the same function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use static variable etc. to store stage of FunctionA.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 00:33:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11486699#M16260</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2022-10-17T00:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11487304#M16261</link>
      <description>&lt;P&gt;Afaik, you cannot chain them directly, but you can easily achieve the same effect:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Subscribe to the Idling event and attach handlerA&lt;/LI&gt;
&lt;LI&gt;In handlerA, unsubscribe from the Idling event, then subscribe to the Idling event and attach handlerB&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on other factors, Revit may or may not execute other actions in between the two event handler calls, but their relative order should be preserved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You say,&lt;SPAN&gt;&amp;nbsp;I cannot assign a new handler because I don't have a valid API context.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Why not? Within the Idling event handler, I thought you &lt;STRONG&gt;&lt;U&gt;do&lt;/U&gt;&lt;/STRONG&gt; have a valid Revit API context.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Question: why do the actions A and B have to be executed separately? Can't you just execute them both within the same Idling event handler?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 08:37:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11487304#M16261</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2022-10-17T08:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11487959#M16262</link>
      <description>&lt;P&gt;You should create a queue service for that, subscribing and unsubscribing Revit events in your App as static.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like this maybe helps: &lt;A href="https://gist.github.com/ricaun/11b272c5bec46f05c3fe49525fcc3fdf" target="_blank"&gt;&lt;STRONG&gt;https://gist.github.com/ricaun/11b272c5bec46f05c3fe49525fcc3fdf&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can register the service in your IExternalApplication.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public class App : IExternalApplication
{
    public static IdlingQueueService IdlingActionService { get; private set; }
    public Result OnStartup(UIControlledApplication application)
    {
        IdlingActionService = new IdlingQueueService(application);
        return Result.Succeeded;
    }

    public Result OnShutdown(UIControlledApplication application)
    {
        IdlingActionService?.Dispose();
        return Result.Succeeded;
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then you could add some Action to run on the Idling Event, each one gonna run in a different Idling Event.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
    {
        App.IdlingActionService.Add((uiapp) =&amp;gt; { System.Windows.MessageBox.Show("1"); });
        App.IdlingActionService.Add((uiapp) =&amp;gt; { System.Windows.MessageBox.Show("2"); });

        return Result.Succeeded;
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 14:13:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11487959#M16262</guid>
      <dc:creator>ricaun</dc:creator>
      <dc:date>2022-10-17T14:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11489054#M16263</link>
      <description>&lt;P&gt;Thank you all for your responses. I have tried 3 different solutions all to no success.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I tried running 1 idling event with block if statements just to perform different actions based on some state variables.&lt;UL&gt;&lt;LI&gt;This fails because one of my functions also ends up giving Revit the opportunity to idle. This causes a never ending idling loop.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;I retried subscribing to a new handler inside of handler A.&lt;UL&gt;&lt;LI&gt;This fails with an error "Cannot subscribe to an event during execution of that event". I am attempting to subscribe to a different handler function with code in the form of below.&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public async void OnIdlingA(object sender, IdlingEventArgs e)
{
     Autodesk.Revit.UI.UIApplication uiapp = sender as 
     Autodesk.Revit.UI.UIApplication;


     Debug.Assert(null != uiapp,
         "expected a valid Revit application instance");

     if (uiapp != null)
     {
          uiapp.Idling -= OnIdlingA;
          uiapp.Idling += new
                EventHandler&amp;lt;Autodesk.Revit.UI.Events.IdlingEventArgs&amp;gt;
                (OnIdlingB);

          await FuncA();
     }
}
​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Finally, I tried the Idling Queue service&lt;UL&gt;&lt;LI&gt;This also fails due the the fact that I am getting extra idling events while my functions are running causing the execution to dive into the idling functions before finishing the current function.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I step back from all the details of my implementation, my problem is really not too complicated. I just wish I could run the Execute function of IExternalCommand like below.&lt;/P&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;&lt;LI-CODE lang="csharp"&gt;public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
      Object1 obj1 = new Object1(commandData)
      
      await obj1.func1;
      await obj1.func2;
      obj1.func3;  //THIS IS THE ONLY REVIT INTERACTION

      return Autodesk.Revit.UI.Result.Succeeded;
}&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;&lt;P&gt;This doesn't work because I can not make the Execute function async but this is the theory. Not being able to await func1 and func2 is what is causing me to dive so deep into idling events. Func1 and Func2 have nothing to do with Revit.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Func1 calls a web server to do authentication in a webview&lt;/P&gt;&lt;P&gt;Func2 calls a web server to download Revit files&lt;/P&gt;&lt;P&gt;Func3 opens those files and uses that data to manipulate the current document.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all for the guidance&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 22:53:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11489054#M16263</guid>
      <dc:creator>ariWZRFQ</dc:creator>
      <dc:date>2022-10-17T22:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11489084#M16264</link>
      <description>&lt;P&gt;You forgot to explain that you are using 'await' functions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Revit does not like async stuff, and your code looks odd. How can you add an await without an async method...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To work with async and Revit use the &lt;A href="https://github.com/KennanChan/Revit.Async" target="_blank" rel="noopener"&gt;Revit.Async&lt;/A&gt; package, so the package gonna manage the Idling stuff.&lt;/P&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;&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>Mon, 17 Oct 2022 22:51:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11489084#M16264</guid>
      <dc:creator>ricaun</dc:creator>
      <dc:date>2022-10-17T22:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11489092#M16265</link>
      <description>&lt;P&gt;Sorry, I just edited my reply for clarity. I am not actually running the functions with await as shown. That is how I would do it if the Execute function could be made async.&lt;BR /&gt;&lt;BR /&gt;Func1 and Func2 are async functions which is why I am/was trying to run them in idling events.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 22:55:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11489092#M16265</guid>
      <dc:creator>ariWZRFQ</dc:creator>
      <dc:date>2022-10-17T22:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11489126#M16266</link>
      <description>&lt;P&gt;One thing that is important is that when an &lt;STRONG&gt;&lt;EM&gt;IExternalCommand&lt;/EM&gt; &lt;/STRONG&gt;is running the Idling is not gonna trigger until the command ends. The Idling means the Revit is not busy doing something and is ready to receive some user interaction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess the best approach in your case should be to use &lt;A href="https://github.com/KennanChan/Revit.Async" target="_blank" rel="noopener nofollow noreferrer"&gt;Revit.Async&lt;/A&gt; package with something like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public async Task Execute()
{
      await func1;
      await func2;
      await RevitTask.RunAsync(func3);  //THIS IS THE ONLY REVIT INTERACTION
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the RevitTask you can run the &lt;STRONG&gt;&lt;EM&gt;func3&lt;/EM&gt; &lt;/STRONG&gt;in Revit context.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 23:24:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11489126#M16266</guid>
      <dc:creator>ricaun</dc:creator>
      <dc:date>2022-10-17T23:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11495672#M16267</link>
      <description>&lt;P&gt;One correct, reliable and effective approach to address the situation you describe is&amp;nbsp;to implement an &lt;U&gt;external event:&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.28" target="_blank"&gt;https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.28&lt;/A&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the event handler, simply run the code to execute&amp;nbsp;func3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the rest has nothing to do with Revit and does not require the Revit API.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore, you can execute it independently, externally, and simply raise the external event after&amp;nbsp;func1 and func2 have completed successfully.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2022 09:47:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11495672#M16267</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2022-10-20T09:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11495690#M16268</link>
      <description>&lt;P&gt;Oh dear. I just noticed your statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;nbsp;&lt;SPAN&gt;Func1 and Func2 are async functions which is why I am/was trying to run them in idling events.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Well, that is just about the opposite of what you could or should do. Or at least it is not intended, afaict.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Revit and its API is single threaded. The Idling event handler is single threaded. So, as long as that event handler is busy executing, e.g., your func1 and func2, it will block Revit from doing anything else.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The purpose of the Idling event is to enable you to execute some action as soon as Revit has stopped being occupied with and therefore blocked by other tasks.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This confirms my preceding answer: it seems to me that an appropriate way to handle this would be to disconnect&amp;nbsp;func1 and func2 from Revit and your add-in as much as possible, and let them trigger an external event when they are completed, to execute func3.&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV class="custom-add-tag"&gt;
&lt;DIV class="lia-panel lia-panel-standard MessageTagsTaplet Chrome lia-component-message-view-widget-tags"&gt;
&lt;DIV class="lia-decoration-border"&gt;
&lt;DIV class="lia-decoration-border-top"&gt;
&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 20 Oct 2022 09:57:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11495690#M16268</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2022-10-20T09:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11497035#M16269</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So what I ended up doing is below. It seems to work but would love some feedback if its unsafe:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The main IExternalCommand Execute function just subscribes to an idling event.&lt;/LI&gt;&lt;LI&gt;The event handler is an async function.&lt;/LI&gt;&lt;LI&gt;In the async event handler function, I await the 3 functions and wrap the third one with RevitTask.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This still feels like the original idling action is unnecessary and I should be able to just dive right into the async func1, but other than that this works!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/824630"&gt;@jeremy_tammik&lt;/a&gt;&amp;nbsp;How would you recommend disconnecting Func1 and Func2? The functions are async in that they use async functions in them but I don't need them to run truly asynchronously. Blocking Revit is fine for them. At all points in my code base, I am awaiting the results of the async functions so that everything runs essentially synchronously. All of my problems are due to the fact that the Revit execute function can not be made "async" so I can not "await" func1 and func2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't imagine that this is the first time this problem has been encountered. It's a pretty standard workflow assuming that other plugins need some sort of authentication. First send an HTTP request to a server, then following a successful response, do all the Revit stuff.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2022 17:34:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11497035#M16269</guid>
      <dc:creator>ariWZRFQ</dc:creator>
      <dc:date>2022-10-20T17:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11497173#M16270</link>
      <description>&lt;P&gt;Yes, this is a standard situation, and I described the standard solution above. No need for async anything, just create an external event X, raise the event when func1 and func2 have completed, and execute func3 in the external event X handler. No Idling needed, no async needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2022 18:25:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11497173#M16270</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2022-10-20T18:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11497193#M16271</link>
      <description>&lt;P&gt;Oh maybe I need to learn more about how async works in C# if its different than JS development.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would expect that if run func1 and func2 without the await flag, func2 will start before func1 has completed and the external event will be raised before func1 and func2 are completed. This would not work for my code since I would be trying to run code before the authentication step (func1) is completed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have I misunderstood? Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2022 18:33:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11497193#M16271</guid>
      <dc:creator>ariWZRFQ</dc:creator>
      <dc:date>2022-10-20T18:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11497202#M16272</link>
      <description>&lt;P&gt;In the context of the Revit. API, I would recommend scrapping async completely. That will totally simplify things.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2022 18:36:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11497202#M16272</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2022-10-20T18:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11497205#M16273</link>
      <description>&lt;P&gt;haha I wish, but I still need to send requests to external servers. I can't think of a way to do that without async.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2022 18:38:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11497205#M16273</guid>
      <dc:creator>ariWZRFQ</dc:creator>
      <dc:date>2022-10-20T18:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11498316#M16274</link>
      <description>&lt;P&gt;Well, I did myself, many times, connecting desktop and cloud:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/FireRatingCloud" target="_blank"&gt;https://github.com/jeremytammik/FireRatingCloud&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not very long ago, async did not exist. Push and pull functionality was up and running for decades before async was invented in the form you know it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history" target="_blank"&gt;https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 07:11:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11498316#M16274</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2022-10-21T07:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11503160#M16275</link>
      <description>&lt;P&gt;As &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4176855"&gt;@ricaun&lt;/a&gt;&amp;nbsp;has mentioned, it seems to be a highly matched case that Revit.Async is designed to solve.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first time I came up with the idea of Revit.Async was in a cloud rfa management system. The main use case was to query the server about the information of an rfa file (your function 1), then download it (your function 2) and finally place it with Revit API (your function 3). I used a pattern similar to Revit.Async to chain them up and it worked like a charm.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would suggest you to take a look at &lt;A href="https://github.com/KennanChan/Revit.Async" target="_blank" rel="noopener"&gt;Revit.Async&lt;/A&gt; and you will not be disappointed.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 05:32:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11503160#M16275</guid>
      <dc:creator>Kennan.Chen</dc:creator>
      <dc:date>2022-10-24T05:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11503342#M16276</link>
      <description>&lt;P&gt;Many thanks to everybody for the interesting discussion and valuable contributions, especially to Kennan for implementing and sharing Revit.Async. I summarised the discussion for posterity on the blog:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2022/10/can-you-avoid-chaining-idling.html#6" target="_blank"&gt;https://thebuildingcoder.typepad.com/blog/2022/10/can-you-avoid-chaining-idling.html#6&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 07:26:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11503342#M16276</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2022-10-24T07:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11508601#M16277</link>
      <description>&lt;P&gt;Thank you all for the suggestions and help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3373609"&gt;@Kennan.Chen&lt;/a&gt;, I have Revit.Async in my code base but I don't think I am using it most effectively. Can you explain what you used for your original use case (so the same structure I would use)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The part that I can't connect is how to enter the async function from the main IExternalCommands Execute function. The below is what I would have thought but I wasn't able to get this to work before so I had to instead add the runMyFunctions() as an idling event handler and then it worked.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            runMyFunctions();
            return Autodesk.Revit.UI.Result.Succeeded;
        }

public async void runMyFunctions()
        {
            await func1();
            await func2();
            await RevitTask.RunAsync(uiapp2 =&amp;gt; {func3();});
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, thank you all for the great help and discussion. Really appreciate everyones insight and it has helped me along immensely.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 03:25:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11508601#M16277</guid>
      <dc:creator>ariWZRFQ</dc:creator>
      <dc:date>2022-10-26T03:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: Can you chain Idling events?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11508828#M16278</link>
      <description>&lt;P&gt;You need to call RevitTask.Initialize(app) in a valid Revit API context to get Revit.Async ready to use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some valid Revit API contexts are:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;IExternalCommand.Execute method&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;IExternalApplication.OnStartup method&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;IExternalEventHandler.Execute method&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Revit API event handlers&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;IUpdater&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In your case, you can initialize Revit.Async in&amp;nbsp;IExternalCommand.Execute method.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 06:33:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11508828#M16278</guid>
      <dc:creator>Kennan.Chen</dc:creator>
      <dc:date>2022-10-26T06:33:27Z</dc:date>
    </item>
  </channel>
</rss>

