PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Characteristics of a thread created in WLanguage
  • Thread and HFSQL
  • Characteristics of WLanguage procedure
  • Lifespan of the thread
  • Managing errors
  • Forbidden processes
  • Stopping a thread
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Starts the execution of a secondary thread. The statement is a non-locking statement: the two processes are run in parallel.
Reminder: A thread is a process run in parallel of current application (main thread). This allows you to run a task in background task for example (backup, ...).
Versions 15 and later
Android This function is now available for Android applications.
New in version 15
Android This function is now available for Android applications.
Android This function is now available for Android applications.
Versions 16 and later
Universal Windows 10 App This function is now available for Windows Phone applications.
New in version 16
Universal Windows 10 App This function is now available for Windows Phone applications.
Universal Windows 10 App This function is now available for Windows Phone applications.
Versions 18 and later
Universal Windows 10 App This function is now available in Windows Store apps mode.
Android Widget This function is now available in Android Widget mode.
New in version 18
Universal Windows 10 App This function is now available in Windows Store apps mode.
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Android Widget This function is now available in Android Widget mode.
Versions 19 and later
iPhone/iPad This function is now available for iPhone/iPad applications.
WINDEVLinux This function is now available for WINDEV applications in Linux.
WEBDEV - Server codeLinux This function is now available for WEBDEV sites in Linux.
New in version 19
iPhone/iPad This function is now available for iPhone/iPad applications.
WINDEVLinux This function is now available for WINDEV applications in Linux.
WEBDEV - Server codeLinux This function is now available for WEBDEV sites in Linux.
iPhone/iPad This function is now available for iPhone/iPad applications.
WINDEVLinux This function is now available for WINDEV applications in Linux.
WEBDEV - Server codeLinux This function is now available for WEBDEV sites in Linux.
Versions 21 and later
Apple Watch This function is now available in Apple Watch mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 21
Apple Watch This function is now available in Apple Watch mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Apple Watch This function is now available in Apple Watch mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Example
ThreadExecute("Thread1", threadNormal, ThreadProcedure)
...
// Call to a global method of a class
ThreadExecute("Thread2", threadNormal, CClass::GlobalMethod)
// Run a thread while passing parameters
sDate is string
sDate = DateSys()
// Run the thread
ThreadExecute("THREADNAME", threadNormal, "pExecQry", sDate)
// Details of the "pExecQry" procedure
// This procedure expects a date in parameter of a query
PROCEDURE pExecQry(sDate)
IF HExecuteQuery(Del_Date, hQueryDefault, sDate) = False THEN
Error(HErrorInfo())
ELSE
HReadFirst(Del_Date)
END
Syntax

Executing a thread by naming it (Compatible syntax) Hide the details

ThreadExecute(<Thread name> , <Options> , <WLanguage procedure> [, <Parameter 1> [... [, <Parameter N>]]])
<Thread name>: Character string (with quotes)
Name that will be given to the thread. This name will be used by all the functions for thread management. This name cannot correspond to an empty string ("")
<Options>: Constant
Mode for starting the thread.
Versions 18 and later
threadWaitForStart
New in version 18
threadWaitForStart
threadWaitForStart
Waits for the actual start of the thread before continuing the execution.
AndroidAndroid Widget Universal Windows 10 AppJava This constant is not available.
Versions 16 and later
threadGlobalContext
New in version 16
threadGlobalContext
threadGlobalContext
Forces the use of the global context of the project if the thread is run from a window. The thread will continue to run until the application is closed.
The window context is used by default, therefore the thread is stopped when closing the window.
Remark: If ThreadExecute is used in a global initialization code (project, class or set) or from any procedure or method called from a global initialization code, this constant has no effect.
AndroidUniversal Windows 10 AppJava This constant is not available.
Universal Windows 10 App This constant is not available.
Versions 18 and later
AndroidJava This constant is now available.
New in version 18
AndroidJava This constant is now available.
AndroidJava This constant is now available.
threadNormalStarts the thread in normal mode. The HFSQL context is copied during the first use of a HFSQL feature.
threadFullCopyHFSQLContext
(Default value)
Triggers the immediate copy of current HFSQL context.
Recommended if the thread must take into account the current positions in the files and queries of caller context.
Universal Windows 10 App This constant is not available.
AndroidAndroid Widget Java The threadFullCopyHFSQLContext constant is not available.
Versions 23 and later
AndroidAndroid Widget Java The threadFullCopyHFSQLContext constant is now available.
New in version 23
AndroidAndroid Widget Java The threadFullCopyHFSQLContext constant is now available.
AndroidAndroid Widget Java The threadFullCopyHFSQLContext constant is now available.
Versions 20 and later
threadLightCopyHFSQLContext
New in version 20
threadLightCopyHFSQLContext
threadLightCopyHFSQLContext
Triggers the immediate copy of part of current HFSQL context.
Only the directories containing the data files in HFSQL Classic mode and/or the connections in HFSQL Client/Server mode are stored.
Universal Windows 10 App This constant is not available.
AndroidAndroid Widget Java This constant is not available.
Versions 23 and later
AndroidAndroid Widget Java This constant is now available.
New in version 23
AndroidAndroid Widget Java This constant is now available.
AndroidAndroid Widget Java This constant is now available.
<WLanguage procedure>: Procedure name
Name of the WLanguage procedure run. This procedure is run in parallel of the application.
<Parameter 1>: Optional
Parameters that will be passed to the procedure. Caution: these parameters are passed by value (and not by reference).
<Parameter N>: Optional
Parameters that will be passed to the procedure. Caution: these parameters are passed by value (and not by reference).
Versions 25 and later
WINDEVWEBDEV - Server codeiPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile

Declaring and executing a Thread variable Hide the details

<Result> = ThreadExecute(<WLanguage procedure> [, <Parameter 1> [... [, <Parameter N>]]] [, <Options>])
<Result>: Thread variable
Thread variable corresponding to the thread executed.
<WLanguage procedure>: Procedure name
Name of the WLanguage procedure run. This procedure is run in parallel of the application.
<Parameter 1>: Optional
Parameters that will be passed to the procedure. Caution: these parameters are passed by value (and not by reference).
<Parameter N>: Optional
Parameters that will be passed to the procedure. Caution: these parameters are passed by value (and not by reference).
<Options>: Optional constant
Mode for starting the thread.
threadWaitForStartWaits for the actual start of the thread before continuing the execution.
Universal Windows 10 App This constant is not available.
threadGlobalContextForces the use of the global context of the project if the thread is run from a window. The thread will continue to run until the application is closed.
The window context is used by default, therefore the thread is stopped when closing the window.
Remark: If ThreadExecute is used in a global initialization code (project, class or set) or from any procedure or method called from a global initialization code, this constant has no effect.
Universal Windows 10 App This constant is not available.
threadNormalStarts the thread in normal mode. The HFSQL context is copied during the first use of a HFSQL feature.
threadFullCopyHFSQLContext
(Default value)
Triggers the immediate copy of current HFSQL context.
Recommended if the thread must take into account the current positions in the files and queries of caller context.
Universal Windows 10 App This constant is not available.
threadLightCopyHFSQLContextTriggers the immediate copy of part of current HFSQL context.
Only the directories containing the data files in HFSQL Classic mode and/or the connections in HFSQL Client/Server mode are stored.
Universal Windows 10 App This constant is not available.
New in version 25
WINDEVWEBDEV - Server codeiPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile

Declaring and executing a Thread variable Hide the details

<Result> = ThreadExecute(<WLanguage procedure> [, <Parameter 1> [... [, <Parameter N>]]] [, <Options>])
<Result>: Thread variable
Thread variable corresponding to the thread executed.
<WLanguage procedure>: Procedure name
Name of the WLanguage procedure run. This procedure is run in parallel of the application.
<Parameter 1>: Optional
Parameters that will be passed to the procedure. Caution: these parameters are passed by value (and not by reference).
<Parameter N>: Optional
Parameters that will be passed to the procedure. Caution: these parameters are passed by value (and not by reference).
<Options>: Optional constant
Mode for starting the thread.
threadWaitForStartWaits for the actual start of the thread before continuing the execution.
Universal Windows 10 App This constant is not available.
threadGlobalContextForces the use of the global context of the project if the thread is run from a window. The thread will continue to run until the application is closed.
The window context is used by default, therefore the thread is stopped when closing the window.
Remark: If ThreadExecute is used in a global initialization code (project, class or set) or from any procedure or method called from a global initialization code, this constant has no effect.
Universal Windows 10 App This constant is not available.
threadNormalStarts the thread in normal mode. The HFSQL context is copied during the first use of a HFSQL feature.
threadFullCopyHFSQLContext
(Default value)
Triggers the immediate copy of current HFSQL context.
Recommended if the thread must take into account the current positions in the files and queries of caller context.
Universal Windows 10 App This constant is not available.
threadLightCopyHFSQLContextTriggers the immediate copy of part of current HFSQL context.
Only the directories containing the data files in HFSQL Classic mode and/or the connections in HFSQL Client/Server mode are stored.
Universal Windows 10 App This constant is not available.
WINDEVWEBDEV - Server codeiPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile

Declaring and executing a Thread variable Hide the details

<Result> = ThreadExecute(<WLanguage procedure> [, <Parameter 1> [... [, <Parameter N>]]] [, <Options>])
<Result>: Thread variable
Thread variable corresponding to the thread executed.
<WLanguage procedure>: Procedure name
Name of the WLanguage procedure run. This procedure is run in parallel of the application.
<Parameter 1>: Optional
Parameters that will be passed to the procedure. Caution: these parameters are passed by value (and not by reference).
<Parameter N>: Optional
Parameters that will be passed to the procedure. Caution: these parameters are passed by value (and not by reference).
<Options>: Optional constant
Mode for starting the thread.
threadWaitForStartWaits for the actual start of the thread before continuing the execution.
Universal Windows 10 App This constant is not available.
threadGlobalContextForces the use of the global context of the project if the thread is run from a window. The thread will continue to run until the application is closed.
The window context is used by default, therefore the thread is stopped when closing the window.
Remark: If ThreadExecute is used in a global initialization code (project, class or set) or from any procedure or method called from a global initialization code, this constant has no effect.
Universal Windows 10 App This constant is not available.
threadNormalStarts the thread in normal mode. The HFSQL context is copied during the first use of a HFSQL feature.
threadFullCopyHFSQLContext
(Default value)
Triggers the immediate copy of current HFSQL context.
Recommended if the thread must take into account the current positions in the files and queries of caller context.
Universal Windows 10 App This constant is not available.
threadLightCopyHFSQLContextTriggers the immediate copy of part of current HFSQL context.
Only the directories containing the data files in HFSQL Classic mode and/or the connections in HFSQL Client/Server mode are stored.
Universal Windows 10 App This constant is not available.
Versions 25 and later
WINDEVWEBDEV - Server codeiPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile

Executing a thread already described (Thread variable) Hide the details

<Result> = ThreadExecute(<Thread>)
<Result>: Thread variable
Thread variable corresponding to the thread executed.
<Thread>: Thread variable
Name of the Thread variable corresponding to the thread to execute.
Caution: If the thread is already being executed or has already been executed, a WLanguage error will appear.
New in version 25
WINDEVWEBDEV - Server codeiPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile

Executing a thread already described (Thread variable) Hide the details

<Result> = ThreadExecute(<Thread>)
<Result>: Thread variable
Thread variable corresponding to the thread executed.
<Thread>: Thread variable
Name of the Thread variable corresponding to the thread to execute.
Caution: If the thread is already being executed or has already been executed, a WLanguage error will appear.
WINDEVWEBDEV - Server codeiPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile

Executing a thread already described (Thread variable) Hide the details

<Result> = ThreadExecute(<Thread>)
<Result>: Thread variable
Thread variable corresponding to the thread executed.
<Thread>: Thread variable
Name of the Thread variable corresponding to the thread to execute.
Caution: If the thread is already being executed or has already been executed, a WLanguage error will appear.
Remarks

Characteristics of a thread created in WLanguage

A thread created in WLanguage can only be a procedure or a class method. The thread cannot correspond to a WLanguage process (code of a control for example).
If the thread is a class method, ThreadExecute must be run from one of the processes of the class (constructor or method).

Thread and HFSQL

When running ThreadExecute, the HFSQL contexts are automatically duplicated: the number of HFSQL contexts is equal to the number of threads currently run. The entire HFSQL context is copied (filter, search condition, ...). The HFSQL context evolves independently in each thread.
This allows you to perform two different browse operations on the same file in two different threads.
Two methods can be used to copy the HFSQL contexts:
  • Full copy of context (by default)
  • Versions 20 and later
    Light copy of context.
    New in version 20
    Light copy of context.
    Light copy of context.
See Managing HFSQL contexts for more details.
Example: A filter is created on the Customer file. ThreadExecute is called to create the CTX2 thread. The Customer file is filtered in each thread. The filter will still be enabled in the CTX2 thread even if the filter is disabled in the main thread.
Caution: If several threads are used on the data files, we advise you to customize the management of HFSQL errors to avoid displaying the default windows. To do so, use HOnError to disable the automatic management of errors or to redirect the management of errors to a custom procedure (without displaying windows). See Assisted management of HFSQL errors for more details.
Remark: From version 19, HFSQL is the new name of HyperFileSQL.

Characteristics of WLanguage procedure

Caution: The calls to Info, Error, ... lock all the threads currently run.
AndroidAndroid Widget Universal Windows 10 AppJava The calls to Info, Error, ... do not lock the threads currently run.
Remark: The parameters passed to the procedure are passed by value and not by reference.

Lifespan of the thread

The thread is automatically stopped at the end of the execution of the WLanguage procedure run by ThreadExecute.
The thread is also stopped in the following cases:
  • if ThreadExecute is called from the code of a window, the thread will be stopped when closing the window.
  • if ThreadExecute is called from a global process (initialization, explicit call in the main context), the thread will be stopped at the end of the application.
  • if ThreadExecute is called in a class method, the thread is stopped when destroying the object.
To force the execution of the thread in the main context, use the threadGlobalContext constant.
To force the thread to stop, use ThreadStop. This function can be used to stop a thread from the main thread.
Remark: Make sure that the threads are stopped (by ThreadState or ThreadWait) before closing the windows or destroying the objects.

Managing errors

A fatal error occurs in the following cases:
  • if the procedure does not exist.
  • if a thread with the same name is currently run.

Forbidden processes

Caution: The following processes cannot be run in the threads:
Caution: it is not allowed to handle the interface (windows, controls, ...) in a secondary thread.
When a secondary thread must interact with the user or update the interface, it must use a process started from the main thread. This process can correspond to:
  • a global procedure of the project or a local procedure (of a window, ...) called by ExecuteMainThread,
  • the event "Request for refreshing the display" of a window run by RequestRefreshUI.
AndroidAndroid Widget

Stopping a thread

ThreadStop is not available in Android.
The full stop of the must be performed by the thread itself, at the end of the WLanguage procedure called by ThreadExecute.
Example:
ThreadExecute("th", threadNormal, ProcThread)
PROCEDURE ProcThread
bThreadAlive is boolean = True
WHILE bThreadAlive

// ... Process

// Test the end condition of the thread
IF <THREAD END CONDITION> THEN
bThreadAlive = False
END
END
Business / GUI classification : Neutral code
Component : wd250vm.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Video threadExecute
https://youtu.be/IThk-OAzffA

https://windevdesenvolvimento.blogspot.com/2019/01/dicas-1996-windev-threads-02.html
amarildo
24 Jan. 2019