Facility Control

 View Only
  • 1.  asyncExec not working as expected.

    Posted 10-09-2019 15:51

    I'm reading the ogscript reference and it says the following:

    asyncExec
    Executes a function outside of the UI current thread.
    This is especially useful for operations that take time to complete. You can use asyncExec to run such
    operations while continuing to execute the rest of your tasks.

    In order to test this behaviour I made the following grid file:

    <?xml version="1.0" encoding="UTF-8"?><abs contexttype="opengear" gridsize="20" id="_top" style="">

       <meta>

          <params/>

       </meta>

       <meta>

          <api>function UselessFunction(integer)

    {

        var c = 0;

        for (var i = 0; i&lt;integer; i++)

        {

            c = i;

        }

    }</api>

       </meta>

       <button buttontype="push" height="120" left="20" name="Press me to halt Dashboard" top="20" width="280">

          <task tasktype="ogscript">ogscript.debug("Working");

    ogscript.asyncExec(UselessFunction(100000000), 0);

    ogscript.debug("Finished");</task>

       </button>

    <button buttontype="push" height="120" left="320" name="Try to press me while the other task runs" top="20" width="280"/>

    </abs>

    As the button titles suggest pressing the left button seems to halt the UI current thread. What am I doing wrong and how would I solve this issue?

    Thanks



  • 2.  RE: asyncExec not working as expected.

    Posted 10-09-2019 16:05

    Hi Tim.

    Your issue is that you are calling your "UselessFunction" instead of passing it.

    If your long-running function takes arguments, you'd need to wrap it in a new function like this:

    <abs contexttype="opengear" gridsize="20" id="_top" style="">
    <meta>
    <params/>
    </meta>
    <meta>
    <api>function UselessFunction(integer)
    {
    ogscript.debug("Busy");
    var c = 0;
    for (var i = 0; i&lt;integer; i++)
    {
    c = i;
    }
    ogscript.debug("Not so busy");
    }</api>
    </meta>
    <button buttontype="push" height="120" left="20" name="Press me to halt Dashboard" top="20" width="280">
    <task tasktype="ogscript">ogscript.debug("Working");
    ogscript.asyncExec(function() { UselessFunction(100000000) }, 0);
    ogscript.debug("Finished");</task>
    </button>
    <button buttontype="push" height="120" left="320" name="Try to press me while the other task runs" top="20" width="280"/>
    </abs>

     

    If it does not, you could pass it directly:

    <abs contexttype="opengear" gridsize="20" id="_top" style="">
    <meta>
    <params/>
    </meta>
    <meta>
    <api>function UselessFunction()
    {
    ogscript.debug("Busy");
    var c = 0;
    for (var i = 0; i&lt;50; i++)
    {
    c = i;
    ogscript.pause(100);
    }
    ogscript.debug("Not so busy");
    }</api>
    </meta>
    <button buttontype="push" height="120" left="20" name="Press me to halt Dashboard" top="20" width="280">
    <task tasktype="ogscript">ogscript.debug("Working");
    ogscript.asyncExec(UselessFunction, 0);
    ogscript.debug("Finished");</task>
    </button>
    <button buttontype="push" height="120" left="320" name="Try to press me while the other task runs" top="20" width="280"/>
    </abs>

    #DashBoard


  • 3.  RE: asyncExec not working as expected.

    Posted 10-11-2019 12:47

    Thank you this worked wonderfully.


    #DashBoard


  • 4.  RE: asyncExec not working as expected.

    Posted 10-21-2019 12:26

    I have a new issue related to this one. I have a function that contains the following loop:

        var path = ogscript.getPanelRelativeURL("../Assets/Images/PLAYERPHOTO/" + team + "/");

        var player;

        for(var i = 1; i <= 5; i++)

        {

            player = GetTextValue("matchup1-player-"+side+i);

            photopath = "bg-u:" + path + team + "_"+ player + ".png";

            ogscript.setStyle("matchup1-playerphoto-"+side+i, photopath);

        }

    Using the method above I call it as such:

    ogscript.asyncExec
    (
    function f()
    {
    ShowTeamPhotos(side);
    },
    0
    );

    However this is still stalling Dashboard for some reason.


    #DashBoard


  • 5.  RE: asyncExec not working as expected.

    Posted 10-21-2019 13:14

    That looks like a proper call to asyncExec. Are these particularly large image files that are being loaded? At a certain point, the UI thread is needed to actually show the images on screen. If the images are substantially larger than what you need (for example, using a 1000x1000 image where you are only showing at 100x100), it can cause processing delays as each image is scaled.

    If your images are an appropriate size, this should proceed relatively quickly. It's possible something else is using-up the UI resources.

    James


    #DashBoard


  • 6.  RE: asyncExec not working as expected.

    Posted 10-21-2019 13:25

    Yes there are six 1080p images being loaded in total (I omitted the 6th one in the code I shared). The reason for me loading the full format is so that I can preview to check that the assets are actually there with the proper file name (and there's hundreds of them).

    Is it possible however that it's not actually calling the asyncExec function? I noticed that after deleting a debug print to the console in the loop and reloading (even rebooting the process entirely) it would still print. It wasn't until adding new debug call in the script file that the old one disappeared and after that it seemed to work like normal.


    #DashBoard


  • 7.  RE: asyncExec not working as expected.

    Posted 10-21-2019 15:15

    When you are modifying pieces of a panel and selecting 'apply changes', DashBoard will only reload one level up in the hierarchy to save time.  If you want to trigger a full rebuild, you can hit "F5" at any time and that should clear-out any remaining processed code.

     

    There is one mistake I see in your posted code - you shouldn't include a name for your anonymous function (no 'f'):

    ogscript.asyncExec
    (
    function()
    {
    ShowTeamPhotos(side);
    },
    0
    );

    #DashBoard


  • 8.  RE: asyncExec not working as expected.

    Posted 10-21-2019 15:25

    "If you want to trigger a full rebuild, you can hit "F5" at any time and that should clear-out any remaining processed code."

    I'm using external files for my functions and import them as API's so I'm well aware that I need to refresh after making changes.

    As I said I noticed that after deleting a debug print (from that external script file) and reloading it would still print, until I changed the code to print more statements. So is it possible that there's some bug that makes asyncExec to not be called properly, since there seems to be some code changes that don't actually seem to trigger a recompile? Please note that it does work just fine with another script file I'm using for something completely different exactly as I laid out in my examples.

    I'm using the Version 8.6.0 2019-05-01 T11:16 BTW.


    #DashBoard