! Smart Package Robot 's Background Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Background Operation >

! Smart Package Robot 's Background Operations

Smart Package Robot 's Parallel Robot Operations

Previous Top Next


MiniRobotLanguage (MRL)

 

Smart Package Robot 's Parallel Robot Operations

 

 

graphic

 

  Intention

 

What are Parallel-Robot Operations and Background Processing good for?

 

Take a look at the picture above. As you can see, many "Smart Package Robot 's" work at the same time.

Having several "Smart Package Robot 's" work at the same time can save you processing time.

 

Especially if you have a Multi-Core-CPU, then each of the Tasks uses his own CPU-Core and therefore makes perfect use of your hardware.

 

Using the Parallel-Robot feature, you can run a lot of things in the background. Some examples are:

 

    start large applications in the background

    check and handle complicated pop-up-windows in the background (prefer DBC.)

    split large scripts in smaller portions that run parallel

    use all cores of your computer (Multi-Core/CPU usage)

    have things done in shorter time

 

 

Is there a difference between a Parallel-Robot and a Background Operation?

 

Yes, there is a technical difference. A Parallel Robot will run as a new process with an own PID. It will be visible in the Windows Task Manager as a separate process.

A Background Operation starts as a so called "thread" and therefore has the same PID.

Background Operations are more efficient in terms of resources.

There is no problem to have 100, 200 or 400 and maybe more Background Operations running at the same time.

Parallel running robots need more system resources therefore you will not use so many under normal circumstances. The main difference is this:

A Background Operation is already defined and somehow "hard-wired". Therefore it will give you an Operation Result - or not.

A Parallel Robot is not hard-wired, it will do just what you want it to do. It will only give you an Operation Result, if you use the PRS.-command. We'll come back on this topic later.

 

 

How can i  start a Parallel-Robot?

 

It's easy. Technically it is just a pair of PRR. and PRE. A short example could look like this:

 

PRR.

 ' Script that the parallel-robot will execute

 ' This is the necessary END for the Parallel robot

 END.

PRE.$$RET

' Here the Main-Robot continues with his script

' $$RET contains the window-handle of the Parallel-Robot

 

 

There are different sorts of Background-Jobs and Parallel Robots. For most of them, you can use the commands:

 

    WRS. - Wait until the Process has ended / is ready.

    GRS. - Get the Result of that Bavkground process, if there is any.

    DRS. - Drop the result of a Background-Operation.

    IRS. / NRS. - Check if an Result is waiting for you

    JRS. / JNS. - Jump if an Result is/not available

    PRS. - Set the Result of an Parallel-Robot Operation.

 

 

Can i receive an result from calculations inside parallel running Robots?

 

Yes - you can!

Second answer: In case of an Parallel-Robot you have to sent it your self - of course.

In case of other Background-Operations, (like SMB.) the command will sent the result of the operation by itself automatically.

 

You can receive a calculation Result from a Parallel-Robot, using the Ticket-Number and the commands WRS. / GRS. etc. See this example:

 

' We start the Parallel Robot

PRR.

 ' This is the Result the Parallel-Robot sends back to us.

 ' Note that we did not specify an ticket number in P1,

 ' because it will be sent to his "father-robot" in this case.

 PRS.|Hallo!

 ENR.

PRE.

' This is the Stack after the Parobot was started

STS.DUMP

' We wait for the Parobot to end.

WRS.

' And get the calculation result

GRS.

' This is the Stack after the Parobot sent his result

STS.DUMP

MBX.!

ENR.

 

To see, how you get an Result from a Background-Operation, take a look at

SMB. - Send Mail Background

or

MPB. - Music Play Background

 

 

Can i receive an result from multiple parallel running Robots?

 

Yes, here is an example:

 

PRR.

 GUT.Please give Result for Robot 1

 PRS.|Result from Robot 1 is: $$000

 ENR.

PRE.

$$ROA=$$001

PRR.

 GUT.Please give Result for Robot 2

 PRS.|Result from Robot 2 is: $$000

 ENR.

PRE.

$$ROB=$$001

STS.DUMP

WRS.$$ROA,$$ROB

GRS.$$ROA

GRS.$$ROB

STS.DUMP

MBX.!

ENR.

 

You will need to put some text in the two input-boxes, when you run that example.

 

Important Note:

 

The parallel-robot will inherit all variables that the starting robot knows at the starting time.

 

In other words:

All variables and Stack-content will be available on the Parallel-Robot immediately.

But from then  each robot continues his work in his own address-space and with its own variables. Technically it looks like this:

 

$$MYA=1001

PRR.

 ' Script that the parallel-robot will execute

 ' This is the END for the Parallel robot

 MBX.$$MYA = 1001

 $$MYA=99

 END.

PRE.$$RET

' Here the Main-Robot continues with his script

' Result will be 1001

MBX.MYA

 

The Main Robot will not execute anything that is between the PRR. and the PRE.

 

And how do i know that the operation was finished and there is an Result available?

 

There are several ways to find that out. The easiest is to simply wait for the background Operation to finish, using the WRS.-command (Wait for Result). You can also use the IRS. / NRS. - Conditional statement.

And theoretically you could call GRS. and check the timeout-flag after that. If it was set, there was no such result available.

 

 

Important Note:

Any result behind an "ticket-number" is stored as long, until you drop it using DRS.

You do not need to wait until the Operation is finished, to drop a result. If you do not need the result of an Operation, you can drop it immediately after you started the background-task. In this case, the robot will internally note that the result is been dropped and drop it immediately when it becomes available.

 

There is an exception:

Of course you only need to drop the Result of an Parallel-Robot (started with PRR. / PRE.) , if you use the PRS,-command to return a Result. If no Result is returned, it does not need to be dropped.

 

Use these commands together with any Background Operation or Parallel-Robot Operation:

    GRS. - Get Result of Operation

    WRS. - Wait until (one or more) Operation(s) is/are finished

    DRS. - Drop Result of Operation if you do not need it.

    IRS. / NRS. Check if an Result is available

    JRS. / JNS. - Jump if an Result is/not available

 

Use this command:

    PRS. - Set the Result of an Parallel-Robot Operation.

 

only for Parallel Robots, to set the Operation Result..

 

Background Operation Example, using SMB.:

 

' Assume that a file "?path\MailConfig.dat"

' is available

SMP.

' It makes mostly sense with attachements

' SMP.attachment=?path\Send-Mail.zip

' Send the Mail, get the ticket number

SMB.

' If we do not specify a ticket number,

' WRS. will automatically remember the last ticket number

' and use it.

WRS.

' If we do not specify a ticket number,

' GRS. will automatically remember the last ticket number

' and use it.

GRS.

DBP.$$000

' If we do not specify a ticket number,

' DRS. will automatically remember the last ticket number

' and use it.

' DRS. free's the Memory location that was used to hold the

' Result of the background operation.

DRS.

ENR.

 

 

 

 

 

Limitations

 

The Parallel-Robot does NOT inherit the E-Mail Configuration for SMA./SMB.

Remember that you can send E-Mails in the background using SMB. without explicit starting a Parallel Robots.

 

There are no limitations about Parallel-Robots starting other Parallel Robots, or Background-Tasks.

 

 

 

See also:

 

    PRR. - Parallel-Robot-Run

    PRE. - Parallelrobot-Run-End

    GRS. - Get Result

    SMB. Send Mail Background