Make Scripts wait their turn?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
headgeek
Newbie
Posts: 8
Joined: Wed Feb 01, 2017 9:11 pm

Make Scripts wait their turn?

Post by headgeek » Wed Aug 09, 2017 8:26 pm

Is there a way to make scripts wait their turn? I am having a problem where multiple scripts want to run at the same time & cause havoc.

Details: I have a script (and copies of the script) that is scheduled to run every minute from 0:00-5:56, 6:06-15:56, 16:06-23:56
In addition to those scripts, I have one that runs ONCE at 6:00 and 16:00 (and should only last 4 minutes). Somehow there is some overlap & they run at the same time.

I have unchecked "Allow Multiple Instances", but I'm thinking that this is only to prevent the same script running twice. I have also searched the forums, but couldn't find anything that relates.

Seems like there is something I'm missing. Any help is greatly appreciated!

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Make Scripts wait their turn?

Post by JRL » Thu Aug 10, 2017 3:07 pm

I don't know a way to use the Scheduler to control your issue. But I have used dialogs to let one script detect that another is running.

Place the following code at the very top of those scripts that conflict. The code will loop if the dialog "WaitYourTurn" exists. The dialog will exist while a script with this code in it is running. When the script stops the dialog will no longer exist and the second script will exit the "WaitYourTurnLoop" loop and create its own dialog that will cause the next script using this process to dwell... etc...

Code: Select all

Label>WaitYourTurnLoop
IfWindowOpen>WaitYourTurn
  Wait>1
  Goto>WaitYourTurnLoop
EndIf
Dialog>WaitYourTurn
EndDialog>WaitYourTurn

zabros2020
Pro Scripter
Posts: 70
Joined: Sun May 03, 2009 11:49 pm
Location: AU

Re: Make Scripts wait their turn?

Post by zabros2020 » Mon Aug 14, 2017 5:54 am

You could use an ini file to tell other scripts to wait...

Somthing like this simply scenario. Depends how many scripts you have running determines complexity:

Code: Select all

'call this sub when the script runs
GoSub>MyTurn,mt1,1
'when done change to 0 for nex script to process
GoSub>MyTurn,mt1,0

SRT>MyTurn
  Let>iniD=C:\Temp
  Let>iniF=C:\Temp\inFile.ini
  Let>mtEnt=%MyTurn_Var_1%
  Let>mtVal=%MyTurn_Var_2%
      
  IfNotDirExists>iniD
    'create
    CreateDir>iniD
  EndIf
  IfNotFileExists>iniF
    LabelToVar>iniFTmp,sTxt
    WriteLn>iniF,res,%sTxt%
  EndIf
  'MyTurn is mt1(script1)
  EditIniFile>%iniF%,MYTURN,%mtEnt%,%mtVal%
  
/*
iniFTmp:
[MYTURN]
mt1=0
mt2=0
mt3=0
*/
END>MyTurn
Loving MS's Capabilities!!!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts