HISE Logo Forum
    • Categories
    • Register
    • Login

    Background Task || Help me understand this please.

    Scheduled Pinned Locked Moved Unsolved Scripting
    9 Posts 2 Posters 93 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ChazroxC
      Chazrox
      last edited by Chazrox

      I have a heavy token parsing function that crashes when I query large directories. I was told to execute this function on a 'background thread' so I've been looking into it. I just need some clarification from someone with experience with this please.

      I have this function:

      inline function onbtnFindTokenControl(component, value)
      {
      
      // Search files here
      
      }
      btnFindToken.setControlCallback(onbtnFindTokenControl);
      
      

      This function is triggered with a Button on my interface labeled "LOAD".

      Based on what i've read so far....is this pretty much how you do this?

      inline function onbtnFindTokenControl(component, value)
      {
      // Search files here
      }
      btnFindToken.setControlCallback(onbtnFindTokenControl);
      BackgroundTask.callOnBackgroundThread(onbtnFindTokenControl);
      
      // I could put this into the button callback and changed my button callback to 
      // a regular inline function.....is this correct?
      
      
      ustkU 1 Reply Last reply Reply Quote 0
      • ustkU
        ustk @Chazrox
        last edited by

        @Chazrox place your parsing code in a separated function. Then in the button callback, call the background task for the parsing function.
        You shouldn't pass the button callback itself

        Hise made me an F5 dude, browser just suffers...

        ChazroxC 1 Reply Last reply Reply Quote 1
        • ChazroxC
          Chazrox @ustk
          last edited by Chazrox

          @ustk Sweet. So other than that, is that pretty much the process?

          I have helper functions that are called inside of my parsing script but exist outside of my function. Do those need to be dealt with specifically or are they automatically handled on the background thread also because they are called from within my background function?

          1 Reply Last reply Reply Quote 0
          • ChazroxC
            Chazrox
            last edited by

            I think im confused how to name the functions properly.....

            Screenshot 2025-11-09 at 12.51.38 AM.png

            Screenshot 2025-11-09 at 12.51.54 AM.png

            ustkU 2 Replies Last reply Reply Quote 0
            • ustkU
              ustk @Chazrox
              last edited by

              @Chazrox You cannot declare a variable that has the same name of an existing function
              The background task is one thing, the function you want to run in the background is another thing, and the button callback is another one.

              place your process in a function like myParsingProcess, then from within the button callback, just call 'bgFindTokens.callOnBackgroundThred(FindTokens)`

              Your button's function looks very weird, because you return when value is false, so you don't need an if statement after that. Also, you will never enter the else (because it means value is false so you already returned.

              Hise made me an F5 dude, browser just suffers...

              1 Reply Last reply Reply Quote 0
              • ustkU
                ustk @Chazrox
                last edited by

                @Chazrox Don't mess around with the timeOut and forwardStatus until you get the simple version working 😉

                const var BGT = Engine.createBackgroundTask("BGT");
                
                
                inline function timeCriticalProcess()
                {
                	Console.print("> VERY CRITICAL :)");
                }
                
                
                
                inline function onButton1Control(component, value)
                {
                	if (value)
                		BGT.callOnBackgroundThread(timeCriticalProcess);
                };
                
                Content.getComponent("Button1").setControlCallback(onButton1Control);
                

                Hise made me an F5 dude, browser just suffers...

                ChazroxC 1 Reply Last reply Reply Quote 0
                • ChazroxC
                  Chazrox @ustk
                  last edited by Chazrox

                  @ustk I ended up figuring it out. I had it all twisted up. lol. I get it a little bit now tho. Thanks! 🙏

                  ustkU 1 Reply Last reply Reply Quote 1
                  • ustkU
                    ustk @Chazrox
                    last edited by

                    @Chazrox I cooked up a little snippet:

                    HiseSnippet 1213.3ocsVktbaaCDFT1LMj8HMyz92Nn5WzMdbjZ7YcSssNrqlDcLlJYZ6ex.QBJgwP.Z.AislL9MnOT8QoOB8MncAI0gskuzLU+PRK1qu8.6hNJY.MNVpPVtcGOhhr9Ba+wB8fpCHLApQMj02Z2qeWR7Y9rgi3z5WPL+fpLdDINlFhrrV4DinVNqhR+7OGTgvIh.5riPn2KYAz2xFxzyNsygugw4GSBocYCmS5MOrQfTTUxkI.rVwtDZDI3LReZKhQrB1nekDO.Y8C18hh1d6Mi1KZ6s5ERKuWOxVA6rWvtkCh1JL3U6FtY4c1ozd6hrdR8PlVp70DMMFLZEY3X+AxyEYN38rXVOHp.hxHevyYGipNfwC6LIGEiPVq1YVFakrL12X2jExld9rL2Wmx.OSi4SZVEtKHU9Q.Iq4fzpYP5419AJ1H8LNF7741MDZpJhDb05WlrnBG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n8gffqZpan3OtrJ9pkUwMWVE2ZYUb6kUwcVVE289Uz7B5iRzxgYWaPnlcpmNc0xpNrajm0sh9O.SzEnqA
                    

                    Hise made me an F5 dude, browser just suffers...

                    ChazroxC 1 Reply Last reply Reply Quote 1
                    • ChazroxC
                      Chazrox @ustk
                      last edited by

                      @ustk aaahhhh here you go! haha. I gotta see this...brb.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post

                      11

                      Online

                      2.0k

                      Users

                      12.8k

                      Topics

                      111.2k

                      Posts