KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Having a method invoke itself in another process
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac & Win
Published On: September 3, 2005

Here is an exercise in starting a new process and executing its code from a single project method:

If (Count parameters=0)
     $proc:=New process(Current method name;1024*32;Current method name;True)
Else
     `rest of method here - will run in the new process
End if

Why would you want to do this?

For example if you don't have a process handler, you may be calling a new process in code in another project method, which convolutes the program flow. This solution helps to minimize project methods, and keeps the design organization and debugging cleaner since you can see what code the new process will run, and can easily trace it with bullet points.

It can also be handy if you just want to test something that takes place in a new process with a specified amount of memory so that you don't have to generate two project methods for the test.

The idea is similar to a project method that is called to do a number of different tasks based on a case statement such as:
Case of
: ($1="initialize")
...
: ($1="process")
...
: ($1="execute")
...
: ($1="terminate")
...
end case