[Perform Task] - excute task in new thread and immediately continue the parent task

254 views
Skip to first unread message

Daniel Bartoníček

unread,
Oct 7, 2016, 4:59:13 PM10/7/16
to Tasker
Hi,

I need to execute long duration task from another task in parallel mode.

Example:

Task 1:
1) do some stuff...
2) Perform Task "Task2" STOP=false, priority=%priority
3) do some stuff...


Task2:
1) Variable set %count = 0;
2) Variable set %count = %count + 1;
3) do something...
4) Wait 1 sec
5) Goto 2) if %count < 120

I need to execute Task 2 in background and continue Task immediately =>There will be two task running in parallel.

Is that possible? Or is there any workaround?

Rich D

unread,
Oct 7, 2016, 8:23:17 PM10/7/16
to Tasker Google Groups Post

> Hi,
>
> I need to execute long duration task from another task in parallel mode.

Welcome to the complex world of task scheduling. This should be easily accomplished by just setting both the parent and child to the same priority. This would cause the tasks to alternate actions unless a wait is encountered. If there is a wait then any task with any priority is allowed to run while the wait is in affect. That is how it worked several versions ago.

However several users were looking for a true subroutine out of the preform task action. IE-- Make it so the child has to be completed before the parent can continue.

So the developer added a  special parent child relationship to the preform task action to ensure this. So this is where we are at for better or worse.... 

There are 2 work arounds for this issue.

The first is to make a profile with a 'variable set' context that will do the preform task action. So whenever you want to do a preform task action you simply set a global variable to the name of the desired task to run. This will trigger the profile and run your task free of the restriction.

The second is to start a second iteration of the child task from with the child task itself. You need to set the task collision settings to 'abort existing task' so when the second iteration runs it kills the first iteration and releases the restriction.  Here is a example of how it would work. 

Parent_pg (784)
<start>
A1: Anchor
A2: Flash [ Text:Parent start Long:Off ]
A3: Perform Task [ Name:Child_pg Priority:%priority Parameter 1 (%par1):1 Parameter 2 (%par2): Return Value Variable: Stop:Off ]
A4: Flash [ Text:Parent end Long:Off ]

Child_pg (785)
Abort Existing Task
A1: Flash [ Text:First iteration Long:Off ] If [ %par1 ~ 1 ]
A2: Flash [ Text:Second iteration Long:Off ] If [ %par1 ~ 2 ]
A3: Perform Task [ Name:Child_pg Priority:%priority Parameter 1 (%par1):2 Parameter 2 (%par2): Return Value Variable: Stop:Off ] If [ %par1 ~ 1 ]
A4: Flash [ Text:Starting child wait Long:Off ]
A5: Wait [ MS:0 Seconds:10 Minutes:0 Hours:0 Days:0 ]
A6: Beep [ Frequency:8000 Duration:1000 Amplitude:50 Stream:3 ]

Daniel Bartoníček

unread,
Oct 8, 2016, 6:37:10 AM10/8/16
to Tasker
Big thanks! - I used the second option and it works like a charm :)

It will be nice to have a option in Perform task action to control this behavior.
Something like "Perform task as a function" (perform task and wait for result) and "Start task" (Perform task in background and immediately continue. Result will not be available)

Dne sobota 8. října 2016 2:23:17 UTC+2 Rich D napsal(a):

Rich D

unread,
Oct 8, 2016, 7:31:35 AM10/8/16
to Tasker Google Groups Post


> Big thanks! - I used the second option and it works like a charm :)
>
> It will be nice to have a option in Perform task action to control this behavior.
> Something like "Perform task as a function" (perform task and wait for result) and "Start task" (Perform task in background and immediately continue. Result will not be available)
>

Yes, I do feel this is issue that should should be addressed. The problem with either of these awkward work arounds is you can no longer use the 'Return' action. I am sure Pent will be very busy with the android N update but hopefully he will eventually be able to get a fix in place.

Rich.. 

CoolRaoul

unread,
Oct 16, 2016, 11:15:22 AM10/16/16
to Tasker


It will be nice to have a option in Perform task action to control this behavior.
Something like "Perform task as a function" (perform task and wait for result) and "Start task" (Perform task in background and immediately continue. Result will not be available)

I strongly approve this feature request ! 

BTW I think that another (maybe simpler) workaround could be done using an intermediate task:
Main task call normally the intermediate task (lets call it "task1") at same priority level (priority = %priority) 
task1 does nothing more then calling the effective task ("task2") with option "stop" set, which makes it returns immediately to the caller according to the built-in help ("When a task is started from an existing task, the existing task continues unless the Stop parameter is set.")
With "stop" set, task1 should immediately return to main task while task2 continue running.
Reply all
Reply to author
Forward
0 new messages