One of the most useful and powerful features in Ubot Studio is that of multi-threading. Take a spin with us as we look at the three different types of threads in Ubot and how you can create some really useful code to make your automation efforts more simplified and running fast.
Multi Threading In Ubot
Lets dive right in this time and take a look at the three types of threads in Ubot along with a cool example to demonstrate the concepts.
You should see in your UI panel, the current running state of the bot, the state of a loop counter, the state of the embedded browser and several start and stop buttons to turn on and off each.
Play with the buttons as well as the main Run and Stop buttons in Ubot.
Main bot thread
The main thread for the bot is executed whenever the user presses the Ubot Run button. It isn't explicitly labeled as a thread statement but it does get executed. This is where you make calls to the high level processing logic of your bot.
UI HTML Thread
Go ahead and turn off the bot by pressing the Stop button. Now, click on the Start Test Variable Spin button. Notice that the test variable state is being updated.
But the bot is off you say.
It is, the main thread of the bot is off, but the UI HTML thread isn't. The UI panel is a component all to itself. It doesn't have to interact with the browser nor be a part of the bot's main thread. This is a perfect place to put code for doing non-related browser processing.
Event Threads
For lack of a better term, I chose event threads.
One of the Ubot customers discovered an interesting way to assign a UI stat monitor to the ubot javascript interpreter.
ui stat monitor("<script type=\"text/javascript\">window.onload = ubot.runScript(\'MainOnLoad()\')</script>", "")
When our bot is executed, this javascript snippet will be executed allowing us to register as a listener to a Javascript onload window event.. I have wired it up to execute a command which contains a looping thread. It will continuously surf to a website until we click the Stop browser button.
Notice that if you attempt to click on the start browser button, the browser no longer navigates. This is because we exited out of the thread loop. In order to get back into the event thread, the onload Javascript event must trigger again. This is because I set the browserRunningState varaible inside the thread and just outside the loop. Hit the browser refresh button and the OnLoad event is again triggered.
Summary
So you have seen three different areas within Ubot where you can creating threading units. The main thread bot which is implicitly invoked, the UI HTML panel, and in events.