4D v16

Processes

Home

 
4D v16
Processes

Processes    


 

 

In addition to the manipulations explained in the video, you should note that: 

A process is an environment that possesses:

  • its own memory space
  • its current selections (one per table)
  • its own variables (process variables)
  • possibly its own interface
  • and so on.

Processes can communicate between themselves in different ways:

  • interprocess variables
  • reading or writing variables
  • etc.

They can:

  • be put to sleep (sleep process)
  • be put in hibernation (suspended process) until another process wakes them up.

A process only dies when the method it executes is completed.
You cannot force a process to die programmatically, even though you can program it to die in certain conditions (see the CALL PROCESS command) 

Processes generally serve the following purposes:

  • create particular processes (batches, “submarine” checks),
  • create tool palettes (independent windows with specific functions),
  • display input/display dialogs so that the user can work with multiple windows.

4D directly generates certain processes.

A process is creating using the New process command:

 vProcessNumber:=New process(Method;Stack;Processname;Settings;...)

This command line must be in the method. We recommend using the concept shown below; you’ll save time and clarity:

 C_TEXT($1)
 If(Count parameters=0) // If no parameter is received, you must create the process
    C_LONGINT(<>ProcessNumber)
    <>ProcessNumber:=New process("Display_Stats2";1024*1024;"Statistics";"Fictitious_Parameter") // create the process
 Else // If the method receives at least one parameter, you need to execute the display method
    C_LONGINT($Window//Create the window (container) in which the dialog is displayed (content)
    $Window:=Open form window("STATS";Plain form window;Horizontally centered;Vertically centered)
    DIALOG("STATS") //Display the dialog
    CLOSE WINDOW($Window// Once the dialog is closed, shut the window
 End if

  • When calling the method (without parameters), 4D creates a process in which it executes a method.
  • The method calls itself (it create a second instance of the method in the new process)
  • and passes itself a parameter:
  • The first method ends
  • while the method executed by the process continues along and presents the statistics array.

As such, you can continue to work while having the statistics window at your fingertips.

To trace the execution of a process (when you execute the New Process line), use the “step-by-step new process” button. This button executes the line and opens a second trace window in which you can follow the progress of the executed method in the process, independently of the calling method.

For example, you can create a process that displays the time and elapsed time since the new process started. This example will give you the basics of setting up a time counter.

Processes allow you to consider quick evolutions in your programming:

  • You can conceptualize your processes,
  • test them in several lines of code,
  • then set them for independent execution in a process.

There are numerous examples of using processes. Here’s one more: you have updates to perform on an important database; however, these updates can be staggered by several seconds or even minutes without having an impact on your company’s performance. So you can:

  • plan on having a table where you save a to-do list of tasks to perform.
  • For each of these tasks, you specify a date, a time, and possibly a priority level and a description of the task to perform (what? on what table? what record? etc.).
  • Then, set in motion a process whose sole mission is to consult this process table and perform the set of tasks for it.
  • When it finishes this, it is suspended until a new task is recorded and the process is re-enabled.

This operation is quite feasible in client / server mode where a process (stored procedure) "runs" on the server and carries out the tasks to be performed:

  • imports
  • reprocessing
  • PDF printing
  • sending of e-mails
  • and so on.

In this video, we're going to learn about the life cycle of a process: birth, life and death.

Processes are often assimilated into multi-tasking jobs. They allow you to create several jobs simultaneously, without having to complete the first process before starting the second.

Let’s say that you want to access the statistic module that we set up in the previous videos. You want it to remain active while you do something else.
To do that, we will start the method in a process and allow the user to refresh the statistics by clicking a button that we’ll add in the form.

First, we're going to create the call to the Statistics dialog in the navigation form. We will:

  • Duplicate a button
  • And call it Stats

and in its method, just like we did for the 1st dialog, we will:

  • Create a container
  • Display the Stats dialog
  • Then close the window again.

Let's test this. We have a Stats button that displays information that interests us and we obtain the statistics.

However, we can no longer work on our navigation form since it is placed in the foreground.

There is a way to work with several windows; in this case, it is preferable to work with several different processes, which is what we're going to do now.

You create a process using the New process command, which must be called from a method.
Then we indicate:

  • which method must be executed in the process
  • the stack
  • the name of the process
  • and any parameters.

In the present case, we're going to create a method for displaying Stats (note that the name is placed in quotes) and this method will contain the creation of the form.

  • The stack doesn't really matter
  • The name of the process will be Statistics
  • And we don't need any specific parameters.

In 4D, there is a star parameter that you can pass as the last parameter and which can be used with many commands. This lets you avoid creating the same process multiple times. We're not going to use it for now, but you can refer to the documentation for more details about its use.

Now let's see how this works. If we click on the Stats button:

  • We still have the Stats form that appears
  • but this time we have the possibility of working in one window or the other.
  • of closing the process
  • of displaying it again
  • and at this level, it is even possible to display several of them since we did not use the star parameter.

It would even be possible, assuming that we configured the year in the form, to have the stats from one year and the stats from another year, on two different screens.

It is important to understand that when we use processes, each one has its own environment; in other words, if we perform a calculation here, we obtain certain items of information regardless of how many records there are.
We can decide to only take a few of them and our statistics will always be calculated based on all information contained in the table.

It is therefore necessary to understand that a process will have:

  • its own selections
  • and its own variables

If we have 2 processes executing the same method, each one can have different information.

When several processes are created and we ask for a trace, 4D shows all the processes that were created:

  • standard processes created by 4D
  • plus the ones that we have created, like the Statistics process.

So it is possible to trace it and when we are going to "calculate", it's the method of the button that we clicked on that is traced.

If we trace another process, we can see the trace mode of this process appear here.

At the beginning of this video, we mentioned the creation, life and death of a process.

Let's look at these 3 stages:
1st, the creation of the process: New process is going to create it.

To trace what is running in a New process, you must use this button: a 2nd trace window appears for tracing the "Statistics" method that is being executed.

Next a method runs and during this period, the process is alive.

  • We can do a number of things such as:
  • inter-process exchanges
  • or drag and drop.

This process is killed when the method that was executed when it was created is finished:

  • Here, we go back to the initial method that was executed when the process was created
  • The window closes
  • The method ends
  • And the process is killed

If we do a trace, we no longer see the "Statistics" process.

 
 

 
PROPERTIES 

Product: 4D
Theme: Processes

 
HISTORY 

 
ARTICLE USAGE

Self-training ( 4D v16)