<?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: How does applicationcommand(&amp;quot;downloadhttprequest&amp;quot;) work? in FlexSim Forum</title>
    <link>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547276#M52714</link>
    <description>&lt;P&gt;Many thanks for your help!&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jun 2019 16:48:54 GMT</pubDate>
    <dc:creator>yue_y</dc:creator>
    <dc:date>2019-06-14T16:48:54Z</dc:date>
    <item>
      <title>How does applicationcommand("downloadhttprequest") work?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547270#M52708</link>
      <description>&lt;P&gt;&lt;I&gt;[ FlexSim 19.1.0 ]&lt;/I&gt;&lt;/P&gt;&lt;P&gt;From this post &lt;A rel="nofollow" href="https://answers.flexsim.com/questions/67068/how-to-make-asynchronous-call-to-web-service.html"&gt;https://answers.flexsim.com/questions/67068/how-to-make-asynchronous-call-to-web-service.html&lt;/A&gt;, I know this command: applicationcommand("downloadhttprequest", verb, server, object, data, silent, filePath, callbackNode) is asynchronous and the callbackNode will be executed after the request has complete. Could someone help me understand how does this function work under the hood? Since FlexSim is single threaded, I assume this function is executed in a separate thread and once it finishes, it will push the callbackNode on top of FlexSim's event queue and get scheduled next. However, in this post &lt;A rel="nofollow" href="https://answers.flexsim.com/questions/67556/is-flexsim-thread-safe.html"&gt;https://answers.flexsim.com/questions/67556/is-flexsim-thread-safe.html&lt;/A&gt; it says FlexSim's event loop is not thread safe, then how is the callbackNode safely added to the event queue?&lt;/P&gt;
&lt;P&gt;Also, not sure if it's related, in the cpp code provided in this post:&lt;A rel="nofollow" href="https://answers.flexsim.com/questions/67556/is-flexsim-thread-safe.html"&gt;https://answers.flexsim.com/questions/67556/is-flexsim-thread-safe.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;There is a line:&lt;/P&gt;
&lt;P&gt;PostMessage(window, FLEXSIM_MESSAGE_USER_NODEFUNCTION, (WPARAM)registernode, NULL)&lt;/P&gt;
&lt;P&gt;Does this line force the registernode to be executed immediately? If so, how does this line interact with FlexSim event loop? Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2019 13:34:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547270#M52708</guid>
      <dc:creator>yue_y</dc:creator>
      <dc:date>2019-06-14T13:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: How does applicationcommand("downloadhttprequest") work?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547271#M52709</link>
      <description>&lt;P&gt;applicationcommand("downloadhttprequest") passes the flag WINHTTP_FLAG_ASYNC to the &lt;A href="https://docs.microsoft.com/en-us/windows/desktop/api/winhttp/nf-winhttp-winhttpopen"&gt;WinHttpOpen&lt;/A&gt; function. Then it passes a callback to the &lt;A href="https://docs.microsoft.com/en-us/windows/desktop/api/winhttp/nf-winhttp-winhttpsetstatuscallback"&gt;WinHttpSetStatusCallback&lt;/A&gt; function. That callback uses PostMessage() to execute the passed treenode callbackNode on FlexSim's main thread, and the http communications happen asynchronously on a separate thread.&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-postmessagea"&gt;PostMessage&lt;/A&gt;(window, FLEXSIM_MESSAGE_USER_NODEFUNCTION, (WPARAM)registernode, NULL) posts a message to FlexSim's main &lt;A href="https://en.wikipedia.org/wiki/Message_loop_in_Microsoft_Windows"&gt;window message loop&lt;/A&gt;. It doesn't execute immediately (you use nodefunction() directly to execute immediately); FlexSim's processing of its Windows messages will execute that node function when it executes that Windows message. A posted window message will happen soon, but not immediately. That line doesn't interact with FlexSim's simulation event loop; it interacts with FlexSim's windows message loop.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2019 15:23:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547271#M52709</guid>
      <dc:creator>philboboADSK</dc:creator>
      <dc:date>2019-06-14T15:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: How does applicationcommand("downloadhttprequest") work?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547272#M52710</link>
      <description>&lt;P&gt;For applicationcommand("downloadhttprequest"), how does FlexSim main thread know the action is complete and it's time to execute the callback? The way I understand FlexSim is that there is a event loop executing event in a queue in the order of time. Since it is single thread, how does the callback function gets in the middle of the loop? Does FlexSim frequently checking a flag or does the call back function pushed to FlexSim event queue?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2019 16:34:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547272#M52710</guid>
      <dc:creator>yue_y</dc:creator>
      <dc:date>2019-06-14T16:34:55Z</dc:date>
    </item>
    <item>
      <title>Re: How does applicationcommand("downloadhttprequest") work?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547273#M52711</link>
      <description>&lt;P&gt;When will FlexSim processes its Windows messages? &lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2019 16:37:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547273#M52711</guid>
      <dc:creator>yue_y</dc:creator>
      <dc:date>2019-06-14T16:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: How does applicationcommand("downloadhttprequest") work?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547274#M52712</link>
      <description>&lt;P&gt;FlexSim is always processing its Windows messages. It is literally a while(1) loop. See the example in &lt;A href="https://en.wikipedia.org/wiki/Message_loop_in_Microsoft_Windows"&gt;Windows message loop&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2019 16:46:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547274#M52712</guid>
      <dc:creator>philboboADSK</dc:creator>
      <dc:date>2019-06-14T16:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: How does applicationcommand("downloadhttprequest") work?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547275#M52713</link>
      <description>&lt;P&gt;FlexSim doesn't have to do anything special to handle it. It is a Windows API command called from a Windows API application. Windows handles it.&lt;/P&gt;&lt;P&gt;If you want to know how it works, contact Microsoft. You don't need to know how the Windows API handles it behind the scenes in order to use it.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2019 16:47:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547275#M52713</guid>
      <dc:creator>philboboADSK</dc:creator>
      <dc:date>2019-06-14T16:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: How does applicationcommand("downloadhttprequest") work?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547276#M52714</link>
      <description>&lt;P&gt;Many thanks for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2019 16:48:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547276#M52714</guid>
      <dc:creator>yue_y</dc:creator>
      <dc:date>2019-06-14T16:48:54Z</dc:date>
    </item>
    <item>
      <title>Re: How does applicationcommand("downloadhttprequest") work?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547277#M52715</link>
      <description>&lt;P&gt;Re-reading your question, I need to clarify:&lt;/P&gt;&lt;P&gt;The callback passed to WinHttpOpen is a C++ function defined in the FlexSim engine.&lt;/P&gt;&lt;P&gt;That C++ callback function uses PostMessage() to execute the callback treenode function on the main thread.&lt;/P&gt;&lt;P&gt;The execution of the treenode callback is handled by FlexSim; the execution of the C++ callback is handled by the Windows API.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2019 17:21:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/how-does-applicationcommand-quot-downloadhttprequest-quot-work/m-p/13547277#M52715</guid>
      <dc:creator>philboboADSK</dc:creator>
      <dc:date>2019-06-14T17:21:54Z</dc:date>
    </item>
  </channel>
</rss>

