VBScript: Start Task and wait for it

Discuss RoboTask here
Post Reply
userXXX
Posts: 58
Joined: Wed Jun 11, 2014 8:45 am

VBScript: Start Task and wait for it

Post by userXXX »

Hello Oleg,

can you please tell me, how to start a task and then wait until it ends in VBScript?
I tried, but I don't know VBScript.

It seems, that between starting a task and checking its status, I need to wait for a few seconds. But I'm not sure.
My version for "Delay" makes the CPU busy, there should be a better way.

Are status 3 and 4 the right values for checking if the task is still running?

Thank you.

Code: Select all

extName = "hallo_task"

num = RoboTaskApp().StartTask(extName, "")

'Delay
mytime = timer
do while timer < mytime + 5
loop

num = RoboTaskApp().TaskNumByExternalName(extName)
if num >=0 then

'Still running?
  st = RoboTaskApp().TaskInfoState(num)
  do while st = 3 or st = 4
    st = RoboTaskApp().TaskInfoState(num)
  loop

  en = RoboTaskApp().TaskEnabled(extName)
  TaskName = RoboTaskApp().TaskInfoName(num)
  RoboTaskApp().DesktopAlert _
    "Task information", _
    "Task Name: " + TaskName + "; " + Chr(10) +  _
    "Task number: " + CStr(num) + "; " + Chr(10) + _
    "Task status: " + Cstr(st) + "(" + stName + "); " + Chr(10) + _
    "Is the task enabled: " + Cstr(en) + ";", _
    0, 0, 10, 0, 100, 3
else
  RoboTaskApp().DesktopAlert _
    "Task information", _
    "Unknown task External name" + chr(10) + _
    "The task desn't exist", _
    2, 0, 10, 0, 100, 3
end if
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: VBScript: Start Task and wait for it

Post by Oleg »

You are correct this script loads processor.
Unfortunately script engine doesn't support some procedures like SLEEP (in order to avoid processor loading)
Maybe we need to add some additional extensions for script actions. I wrote this into our ToDo and we'll discuss this.

But now I recommend you to divide your actions
Why do you want to put everything into VB script?

I recommend you to use such algorithm:
Start task with waiting
VB Script // do the rest script when task finish
Oleg Yershov
Post Reply