Thread

From UBot Studio
(Difference between revisions)
Jump to: navigation, search
(Example)
(Example)
Line 21: Line 21:
  
 
[[File:thread.jpg]]
 
[[File:thread.jpg]]
 +
 +
 +
 +
This example demonstrates how multiple tasks can be run in different windows within UBot Studio.
 +
 +
Place this define command in a separate tab. The define simply clears the lists within it whenever its command is run.
 +
 +
<pre>
 +
define clear lists {
 +
    clear list(%ha)
 +
    clear list(%ho)
 +
    clear list(%hee)
 +
    clear list(%har)
 +
}
 +
 +
</pre>
 +
 +
 +
In a separate tab, the loop commands for each list being displayed in the browser is placed within a thread command.
 +
 +
 +
<pre>
 +
clear lists()
 +
thread {
 +
    loop(5) {
 +
        add item to list(%ha, "ha", "Don\'t Delete", "Global")
 +
        load html($text from list(%ha, "<br />"))
 +
        wait($rand(1, 3))
 +
    }
 +
}
 +
thread {
 +
    in new browser {
 +
        loop(5) {
 +
            add item to list(%ho, "ho", "Don\'t Delete", "Global")
 +
            load html($text from list(%ho, "<br />"))
 +
            wait($rand(1, 3))
 +
        }
 +
    }
 +
}
 +
thread {
 +
    in new browser {
 +
        loop(5) {
 +
            add item to list(%hee, "hee", "Don\'t Delete", "Global")
 +
            load html($text from list(%hee, "<br />"))
 +
            wait($rand(1, 3))
 +
        }
 +
    }
 +
}
 +
thread {
 +
    in new browser {
 +
        loop(5) {
 +
            add item to list(%har, "har", "Don\'t Delete", "Global")
 +
            load html($text from list(%har, "<br />"))
 +
            wait($rand(1, 3))
 +
        }
 +
    }
 +
}
 +
</pre>
 +
 +
 +
When the script is run, notice that multiple windows open, and each list displays its items simultaneously and individually within each window.
 +
 +
 +
[[File:threading.gif]]

Revision as of 19:43, 6 November 2013

This command is a Flow Command. This command runs the contained commands in a separate thread from the main script allowing multiple commands to run at the same time. (Professional and Developer Editions Only)


Example

thread {
    in new browser {
        navigate("http://www.google.com", "Wait")
        wait(3)
    }
}
navigate("http://www.bing.com", "Wait")


Running the script will open a new browser window and navigate to google, while simultaneously navigating to bing in the main browser.

The thread command makes the simultaneous running of each command possible.


Thread.jpg


This example demonstrates how multiple tasks can be run in different windows within UBot Studio.

Place this define command in a separate tab. The define simply clears the lists within it whenever its command is run.

define clear lists {
    clear list(%ha)
    clear list(%ho)
    clear list(%hee)
    clear list(%har)
}


In a separate tab, the loop commands for each list being displayed in the browser is placed within a thread command.


clear lists()
thread {
    loop(5) {
        add item to list(%ha, "ha", "Don\'t Delete", "Global")
        load html($text from list(%ha, "<br />"))
        wait($rand(1, 3))
    }
}
thread {
    in new browser {
        loop(5) {
            add item to list(%ho, "ho", "Don\'t Delete", "Global")
            load html($text from list(%ho, "<br />"))
            wait($rand(1, 3))
        }
    }
}
thread {
    in new browser {
        loop(5) {
            add item to list(%hee, "hee", "Don\'t Delete", "Global")
            load html($text from list(%hee, "<br />"))
            wait($rand(1, 3))
        }
    }
}
thread {
    in new browser {
        loop(5) {
            add item to list(%har, "har", "Don\'t Delete", "Global")
            load html($text from list(%har, "<br />"))
            wait($rand(1, 3))
        }
    }
}


When the script is run, notice that multiple windows open, and each list displays its items simultaneously and individually within each window.


Threading.gif

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox