Start([Param: Variant = Null]);
Param. Parameter value that will be passed to the executed method.
The Start method starts the stream for execution.
When the Start method is called, the custom method is started for execution that was specified in the Create constructor. If the custom method has a parameter in its signature, one can use Param to pass the required value or array odf values to the method.
Executing the example requires that the repository contains a unit with the M_THREAD_CALC identifier. The specified methods are implemented in the unit.
Add a link to the Fore system assembly.
Sub UserProc;
Var
Method: IForeMethod;
Th1, Th2: IForeThread;
Begin
Method := New ForeMethod.Create;
Method.Assembly := "M_THREAD_CALC";
Method.Method := "Init";
//Create a thread
Th1 := New ForeThread.Create(Method);
Th1.Name := "Prepare to calculate";
Th1.Start;
//Wait until the Init method end in thread
Th1.Join;
//Create threads based on the Calculate method
Method.Method := "Calculate";
Th1 := New ForeThread.Create(Method);
Th1.Name := "General calculation";
Th2 := New ForeThread.Create(Method);
Th2.Name := "High-precision calculation";
//Start parallel execution of threads with different parameter values
Th1.Start(0.00001);
Th2.Start(0.0000001);
While (Th1.State = ForeThreadState.Running) Or (Th2.State = ForeThreadState.Running) Do
//...
//Monitor thread state
//...
End While;
Debug.WriteLine("End");
End Sub UserProc;
Sub Init;
Begin
Debug.WriteLine("Init");
//...
//Prepare to calculate
//...
End Sub Init;
Sub Calculate(Error: Double);
Begin
Debug.WriteLine(Error);
//...
//Operations to execute some calculation
//...
End Sub Calculate;
Executing the example creates a thread connected with the Init custom method. The thread will be started, the current code will wait until thread execution end. After this, two threads are created that are connected with the Calculate custom method. The threads are started in parallel with different parameter values. The thread state is monitored in the cycle until the threads are completed.
See also: