New process

4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next

version 2004.3 (Modified)


New process (method; stack{; name{; param{; param2; ...; paramN}{; *}}}) Number

ParameterTypeDescription
methodStringMethod to be executed within the process
stackNumberStack size in bytes
nameStringName of the process created
paramExpressionParameter(s) to the method
*Unique process
Function resultNumberProcess number for newly created process
or already executing process

Description

The New process command starts a new process (on the same machine) and returns the process number for that process.

If the process could not be created (for example, if there is not enough memory), New process returns zero (0) and an error is generated. You can catch this error using an error-handling method installed using ON ERR CALL.

Process Method: In method, you pass the name of the process method for the new process. After 4D has set up the context for the new process, it starts executing this method, which therefore becomes the process method.

Process Stack: In stack, you pass the amount of memory allocated for the stack of the process. It is the space in memory used to "pile up" method calls, local variables, parameters in subroutines, and stacked records. It is expressed in bytes; it is recommended to pass at least 64K (around 64,000 bytes), but you can pass more if the process can perform large chain calls (subroutines calling subroutines in cascade). For example, you can pass 200K (around 200000 bytes), if necesary.

Note: The stack is NOT the total memory for the process. Processes share memory for records, interprocess variables, and so on. A process also uses extra memory for storing its process variables. The stack contains various 4D informations ; the amount of information kept on the stack depends on the number of nested methods calls the process will employ, the number of forms that it will open before closing them and the number and size of local variables used in each nested method call.

Process Name: You pass the name of the new process in name. This name will appear in the list of processes of the Runtime Explorer and will be returned by the command PROCESS PROPERTIES when applied to this new process. A process name can be up to 31 characters long. You can omit this parameter; if you do so, the name of the process will be the empty string. You can make a process local in scope by prefixing its name with the dollar sign ($).

Important: Remember that local processes should not access data in Client/Server.

Parameter to Process Method: Starting with version 6, you can pass parameters to the process method. You can pass parameters in the same way as you would pass them to a subroutine. However, there is a restriction—you cannot pass pointer expressions. Also, remember that arrays cannot be passed as parameters to a method. Upon starting execution in the context of the new process, the process method receives the parameters values in $1, $2, etc.

Note: If you pass parameters to the process method, you must pass the name parameter; it cannot be omitted in this case.

The optional * parameter: Specifying this last parameter tells 4D to first check whether or not a process with the name you passed in name is already running. If it is, 4D does not start a new process and returns the process number of the process with that name.

Example

Given the following project method:

      ` ADD CUSTOMERS
   SET MENU BAR (1)
   Repeat
      ADD RECORD([Customers];*)
   Until (OK=0)

If you attach this project method to a custom menu item Menu Bar Editor window whose Start a New Process property is set, 4D will automatically start a new process running that method. The call SET MENU BAR(1) adds a menu bar to the new process. In the absence of any window (that you could open with Open window), the call to ADD RECORD will automatically open one.

To be able to start this Add Customers process when you click on a button in a custom control panel, you can write:

      ` bAddCustomers button object method
   $vlProcessID:=New process("Add Customers";32*1024;"Adding Customers")

The button does the same thing as the custom menu item.

While choosing the menu item or clicking the button, if you want to start the process (if it does not exist) or bring it to the front (if it is already running), you can create the method START ADD CUSTOMERS:

      ` START ADD CUSTOMERS
   $vlProcessID:=New process("Add Customers";64*1024;"Adding Customers";*)
   If ($vlProcessID#0)
      BRING TO FRONT ($vlProcessID)
   End if

The object method of the bAddCustomers becomes:

      ` bAddCustomers button object method
   START ADD CUSTOMERS

In the Menu Bar editor, you replace the method ADD CUSTOMERS with the method START ADD CUSTOMERS, and you deselect the Start a New Process property for the menu item.

See Also

Execute on server, Methods, Processes, Project Methods, Variables.


4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next