IForeThread.Sleep

Syntax

Sleep(timeout: Integer);

Parameters

timeout. Pause time in milliseconds.

Description

The Sleep method pauses thread execution for the specified number of milliseconds.

Comments

To avoid locking of the main application, the Sleep method must be called for thread within the custom method, with which the thread is connected. The thread can be sent to the custom method using a parameter in the Start method. When the thread execution is paused, thread state remains unchanged.

Example

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;
    Th: IForeThread;
Begin
    Method := 
New ForeMethod.Create;
    Method.Assembly := 
"M_THREAD_CALC";
    Method.Method := 
"SecTimer";
    Th := 
New ForeThread.Create(Method);
    
//Start timer in separate thread
    Th.Start(Th);
    
//...
    //Continue main program with the ability to monitor thread state
    //...
End Sub UserProc;

Sub SecTimer(Param: Variant);
Var
    Th: IForeThread;
    i: Integer;
Begin
    Th := Param 
As IForeThread;
    For i := 1 To 10 Do
        Th.Sleep(1000);
        Debug.WriteLine(DateTime.Now.TimeOfDay.ToString);
        
//...
        //Some operations with 1 second delay
        //...
    
End For;
End Sub SecTimer;

Executing the example creates the thread connected with the SecTimer custom method. The thread is started in parallel with the main application thread. Some code with 1 second delay can be executed within the SecTimer method. The thread state can be monitored in the main application.

See also:

IForeThread