Page 1 of 1

Order Active Tasks

Posted: Fri Aug 27, 2010 1:18 am
by EliasLor
I have about 21 tasks that I'm executing and they can
execute at different times, but sometimes may execute while
another task is executing. What I need to do is to be able
to tell Robotask to execute in order. So basically task 1
executes then task 2 executes, I want task 2 to wait for
task 1 to finish. And if there were 3 then task 3 would
wait for task 2 which would wait for task 1. Any ideas?
Thanks.

Order Active Tasks

Posted: Fri Aug 27, 2010 1:41 am
by Oleg
There is "Wait for task" action for this purpose. Look at the "Task Commands" group.
This action waits until selected task will be finished.

If specified task is not running, the task continue execution without waiting.

Order Active Tasks

Posted: Fri Aug 27, 2010 1:47 am
by EliasLor
I tried that but that doesn't solve the problem. If you
tell robotask to wait for another process then when you
run the 1st task then the second task is waiting for the
1st, that's o.k. But if you run a 3rd task while the
first one is still running, then the 2nd task will be
waiting for the 1st and 3rd task, and the 3rd task will
be waiting for the 1st and 2nd task, so the 2nd and 3rd
task end up waiting for each other forever....3rd
task...waiting for 2nd task, 2nd task waiting for 3rd
task : if 2nd and 3rd task both execute while first task
is still running. See the problem, you can't order based
on the order of execution. Which should be run tasks in
the order they were executed, that command is not there.
There should be somekind of logical way to do it.

Order Active Tasks

Posted: Fri Aug 27, 2010 2:13 am
by Oleg
It seems you got a "deadlock"
1-st task waits for 2-nd task, 2-nd task waits for 3-d, and 3-rd waits for 1-st task (or something similar). This is closed disk.

You can wait not infinity time. Wait only 30 seconds (for example). If selected task will not be done after 30 sec., your task will be cancelled with error "Timeout is over". In other words you MUST cancel your task if critical task is not finished. Otherwise you can get the deadlock.

Next way:
You simply can run necessary tasks sequentially with waiting for finish. See "Start Task" action.

Order Active Tasks

Posted: Sat Aug 28, 2010 8:07 pm
by EliasLor
Oleg,

        Your solution works if you run the tasks in order
but if you are running tasks randomly or out of order I
found a better solution(or so I think). What I figured
out was this. What I did was this...I created a global
variable called GT(or Global Tasks) as a counter and set
it to 0. Then I created a local variable FOUND and set it
to 0. When the task executes it increments the global
variable GT by One, so when the first tasks executes GT
equals 1. Then the task checks GT and if GT equals 1 it
continues but if another task executes and increments GT
to 2 then when that task checks for GT and finds 2, it
will pause for the length of the first task and so on, so
you can have 7 tasks running at the same time and each
task will pause the amount of time of each task, so if
you execute 7 tasks in a row, 1,2,3,4,5,6,7 by the time
it gets to the 7th task GT = 7 and that task will Pause 7
* the amount of time it takes to run a task. And the
found variable will tell the task to wait that amount of
time before executing. When each task is done it will
subtract 1 from the GT variable until it is back to 0 so
the GT counter will always successfully keep track of how
many tasks are running. And the found local variable will
tell each task how long to pause and will reset to 0 at
the beginning of the execution of each task. Basically by
creating a local variable and a global variable to keep
track of the number of tasks that are running this will
allow it to run the tasks in the order that they were
executed. The only problem I found is the amount of time
it takes to increment GT, if you execute 2 tasks at the
exact same time it will successfully pause 1 task until
the completion of the other, but if you run 3 tasks at
the exact same time the program can not increment GT
correctly, as long as you don't run more than 2 at the
exact same time this solution will work, but otherwise
you can run as many tasks as you want with this solution
as long as the pause command * GT(or global tasks
running) accurately keeps track of how much time it takes
to complete the execution of each task. It would be nice
if Robotask had better documentation on how to declare
and use local and global variables...ie using {} for
declaration and not using {} for codeing, and how this
syntax is appropriate for local and global variable
codeing. In anycase the above solution does work and I
have successfully implemented it for my needs. Hope this
helps.

Order Active Tasks

Posted: Sun Aug 29, 2010 12:06 am
by Oleg
See the chapter about local variables here

the same information is in local help file.