|
- Characteristics of a thread created in WLanguage
- Thread and HFSQL
- Characteristics of WLanguage procedure
- Lifecycle of a thread
- Error management
- Forbidden processes
- Stopping a thread
ThreadExecute (Function) In french: ThreadExecute
ThreadExécute("Thread1", threadNormal, ThreadProcedure) ... // Call to a global method of a class ThreadExécute("Thread2", threadNormal, CClass::GlobalMethod)
// Run a thread while passing parameters sDate is string sDate = DateSys() // Run the thread ThreadExécute("THREADNAME", threadNormal, "pExecQry", sDate)
// Details of the "pExecQry" procedure // This procedure expects a date as parameter of a query PROCÉDURE 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>]]])
Versions 25 and later New in version 25 Versions 25 and later New in version 25Remarks 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 HFSQL contexts are automatically duplicated when ThreadExecute is executed: the number of HFSQL contexts is equal to the number of threads currently run. The entire HFSQL context is copied (filter, search condition, etc.). The HFSQL context evolves independently in each thread. This allows you, for example, to perform two different browse operations on the same data file in two different threads. Two methods can be used to copy HFSQL contexts: - Full copy of context (by default)
Versions 20 and laterLight copy of context. New in version 20Light copy of context. Light copy of context.
Example: - A filter is created on the Customer data file.
- ThreadExecute is called to create the CTX2 thread.
- The Customer data file is filtered in each thread (main and CTX2). The filter will still be enabled in the CTX2 thread even if the filter is disabled in the main thread.
Special cases: - Assisted management of HFSQL errors: 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). For more details, see Assisted HFSQL error handling.
- Write operations and assignments in a thread: If values are written or assigned in a thread, the other running threads do not share this information. Some inconsistencies may occur.
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. Remark: The parameters passed to the procedure are passed by value and not by reference. The thread is automatically stopped at the end of the execution of the WLanguage procedure started 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 the window is closed.
- if ThreadExecute is called from a global process (initialization, explicit call in the main context), the thread will be stopped when the application is terminated.
- if ThreadExecute is called in a class method, the thread is stopped when the object is destroyed.
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. A fatal error occurs in the following cases: - if the procedure does not exist.
- if a thread with the same name is currently running.
Forbidden processes Caution: The following processes cannot be run in the threads: - opening windows with WLanguage functions such as Open, Use, Close, ... A specific management mode must be implemented if some windows must be handled in threads (rare case). For more details, see Opening a window in a secondary thread.
- managing events.
- multitask.
- managing timers.
| Caution: UI elements (windows, controls, etc.) cannot be manipulated in a secondary thread. When a secondary thread must interact with the user or update the UI, 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, etc.) called by ExecuteMainThread,
- the event "Request for refreshing the display" of a window run by RequestRefreshUI.
|
Business / UI classification: Neutral code
This page is also available for…
|
|
|
| |
| | https://youtu.be/IThk-OAzffA
https://windevdesenvolvimento.blogspot.com/2019/01/dicas-1996-windev-threads-02.html |
|
|
|
| |
| |
| |
| |
| |
| |
| | |
| |