Sign in to follow this  
Followers 0
tom13

2 loops at the same time

6 posts in this topic

Hi,

At the moment I have 2 loops running at the same time by starting 2 programs at the same time, for example:

Loop 1:

While 1
Sleep(random(120000,150000))
Send("{SPACE}")
WEnd

I want this because the I need to be sure that <space> is pressed every 120-150 seconds and the timer should not have to wait for the second loop, so I made 2 scripts and let them run at the same time. But is it possible to create the same effect (2 loops at the same time) with just 1 script?

Share this post


Link to post
Share on other sites



Hi,

At the moment I have 2 loops running at the same time by starting 2 programs at the same time, for example:

Loop 1:

While 1
Sleep(random(120000,150000))
Send("{SPACE}")
WEnd

I want this because the I need to be sure that <space> is pressed every 120-150 seconds and the timer should not have to wait for the second loop, so I made 2 scripts and let them run at the same time. But is it possible to create the same effect (2 loops at the same time) with just 1 script?

Have a look at AdlibEnable in the help


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

or use timers...

Dim $nTimer1 = TimerInit()
Dim $nTimer2 = TimerInit(), $nTimer2_diff = Random(1000,5000,1)

While 1
   If TimerDiff($nTimer1) > 500 Then
      ; every ~ 500msec
      ConsoleWrite("Event 1" & @CRLF)
      $nTimer1 = TimerInit()
   EndIf
   
   If TimerDiff($nTimer2) > $nTimer2_diff Then
      ; every 1000 to 5000 msec
      ConsoleWrite("Event 2" & @CRLF)
      $nTimer2 = TimerInit()
      $nTimer2_diff = Random(1000,5000,1)
   EndIf
   Sleep(10)
WEnd

CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map

Share this post


Link to post
Share on other sites

Have a look at AdlibEnable in the help

The help says this:

The adlib function should be kept simple as it is executed often and during this time the main script is paused.

That means that they aren't active at the same time right?

Share this post


Link to post
Share on other sites

no their not active at the same time.

but its the same with 2 processes.

the cpu only executes one context at a time...

so unless you need to use some blocking features you should be able to achieve what you want.

but if you want to use 2 processes which could give you a little speed gain you could look

into CoProc (link in my sig) which makes it a bit easier to have multiple processes form one script...


CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map

Share this post


Link to post
Share on other sites

Seems like you wish to have two threads :-) which is not possible in AutoIt (but everybody would like to have it :-D).

So you probably have to stick with two programs or use something like timers as piccaso suggested.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0