ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / Editors / Code editor
  • Overview
  • How to?
  • Automating a procedure
  • Timers / Scheduled procedures
  • Threads: thread (for compatibility) and secure thread
  • Case of main thread
  • Remarks
  • Summary table
  • "At the end of the event containing the call"
  • Stopping an automatic procedure
  • Procedure with automatic start of threads
  • Object-Oriented Programming (OOP)
  • Limitation for WEBDEV
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
The programming of timers, threads and delayed procedures is now automatically managed by the environment.
No need to program the processes and to synchronize them via the WLanguage code anymore, all you have to do is configure the automated procedure options.
No more TimerSys, Timer, ThreadExecute, ... These functions are still available for backward compatibility.
Some examples of processes that can be defined without a single line of code:
  • run a procedure every 10 seconds (check an email box, check the presence of a file on the network, ...)
  • same, but starting 5 minutes after the program is run.
  • run the procedure in background task (in a thread), without waiting for its return value.
WEBDEV - Server code This mechanism can also be used to run scheduled tasks and delayed tasks on the WEBDEV Application Server. For more details, see Scheduled tasks and delayed tasks.
How to?

Automating a procedure

To automate a procedure:
  1. Display the code of the procedure.
  2. Open the description window of the procedure automations:
    • Click Icon in the procedure bar.
    • Select "Configure the automated processes of the procedure" in the context menu of the procedure ("Project explorer" pane).
    • Select "Properties" in the context menu of the procedure in the "Code" pane.
  3. In the window that appears, select the automation type:

Timers / Scheduled procedures

The options are as follows:
  • Number of times:
    Number of times
    The procedure can be run:
    • once: the procedure will be automatically stopped after its execution.
    • several times: the procedure will be run several times in a row. In this case, the procedure executions can be spaced out. A timer will be automatically implemented.
  • Spacing between calls: For a multiple or infinite execution, this option allows you to define the delay between 2 executions.
    • an infinite number of times: the procedure will be run an endless number of times. In this case, the procedure executions can be spaced out. A timer will be automatically implemented.
  • You can configure the subsequent procedure calls:
    • Ignore the timer and run the procedure immediately:
      In this case, only one timer is running. Any other call immediately runs the procedure.
      Example: automatic refresh every minute, run immediately if F5 is pressed.
    • Trigger a new timer:
      In this case, several timers run simultaneously.
      Example: trigger a polling on elements passed as parameters.
    • Restart the existing timer:
      The current timer is stopped and then restarted, the delay before the next execution is reset to zero..
      Example: trigger an operation when the user stops typing on the keyboard.
  • When:
    When
    The procedure can be run:
    • immediately: the procedure is run as soon as it is called in the code.
    • with an automatic start: the procedure is run automatically after the initialization code (of window, page or project).
    • later: the procedure is run after the specified period.
      If the execution is delayed, this interval of time can be kept (or not) for the future calls to this procedure.
    • at the end of process containing the call: the procedure is run when the process containing the call to the procedure is over.
    • at the end of event containing the call: the procedure is run when the process containing the call to the procedure is over. For more details, see "At the end of the event containing the call".
WEBDEV - Server code Remark: Timers are not available in WEBDEV. The automated processes for repetition and for delayed execution are not available. However, the use of a repeated automatic procedure can be configured because a set of procedures, a class, ... can be shared between several products.

Threads: thread (for compatibility) and secure thread

This option is used to specify whether the procedure must be run in the background (in a thread).
Secure thread:
When a thread is secure:
  • a compilation error occurs if the controls are manipulated in the thread (or if the procedure is combined with the "UI" attribute).
  • an exception is thrown:
    • when controls are accessed,
    • if the ThreadStop function is called.
  • when the window that triggered the thread is closed, a request to stop the thread is generated (but the thread continues to run after the window is closed).
The options are as follows:
  • Number of times:
    Number of times
    The procedure can:
    • be run once: the procedure will be automatically stopped after its execution.
    • be run several times: the procedure will be run several times in a row. In this case, the procedure executions can be spaced out. A timer will be automatically implemented.
    • be run an endless number of times: the procedure will be run an endless number of times. In this case, the procedure executions can be spaced out. A timer will be automatically implemented.
    • use HFSQL or not: This option is used to specify whether the thread must access the HFSQL data files.
      Two types of access are available:
      • Full copy of context: Used copy the context of connections, positions, queries, ...
      • Light copy of context: Used to copy the context of connections only.
  • When:
    When
    The procedure can be run:
    • immediately: the procedure is run as soon as it is called in the code and automatically after the initialization code (if "Automatic execution after the initialization code" was checked).
    • later: the procedure is run after the specified period.
      If the execution is delayed, this interval of time can be kept (or not) for the future calls to this procedure.
    • at the end of process containing the call: the procedure is run when the process containing the call to the procedure is over.
    • at the end of event containing the call: the procedure is run when the process containing the call to the procedure is over. For more details, see "At the end of the event containing the call".

Case of main thread

This option allows you to call a procedure in the main thread from a secondary thread. This option is mainly used to access the UI.
There are two modes available:
  • Synchronous mode: The secondary thread waits for the execution of the procedure in the main thread to end before continuing execution. This option is equivalent to ExecuteMainThread.
  • Asynchronous mode: The secondary thread does not wait for the execution of the procedure in the main thread to end before continuing execution. This option is equivalent to ExecuteMainThreadAsynchronous.
Remarks

Summary table

The following table presents the different cases for running procedures according to the selected automated options:
Next calls without keeping the interval of time or the timeoutNext calls while keeping the interval of time or the timeout
Delayed procedure ("Delayed" checked)1st manual callTimeout then run the procedureTimeout then run the procedure
Next callsRun the procedureTimeout then run the procedure
Delayed procedure, repeated with timeout ("Delayed", "Infinite" and "Space out the calls" checked)1st manual callTimeout -> Procedure -> Timeout-> Procedure ...Timeout -> Procedure -> Timeout-> Procedure ...
Next callsRun the procedure (once only)Timeout -> Procedure -> Timeout-> Procedure ...
Delayed procedure, automatically run ("Delayed" and "Automatic execution..." checked)Automatic 1st callTimeout then run the procedureTimeout then run the procedure
Next callsRun the procedureTimeout then run the procedure
Delayed procedure, automatically run, repeated with timeout ("Delayed", "Infinite", "Space out the calls" and "Automatic execution..." checked)Automatic 1st callTimeout -> Procedure -> Timeout-> Procedure ...Timeout -> Procedure -> Timeout-> Procedure ...
Next callsRun the procedure (once only)Timeout -> Procedure -> Timeout-> Procedure ...

"At the end of the event containing the call"

The procedures with the option "At the end of the event containing the call" enabled, and called from a callback procedure (procedure used by fListFile, Event, etc.) are executed at the end of each call to the callback.
Example:
// -----------------
// standard case
// -----------------
Click of button
// beginning of button click code
Proc1
// beginning of Procedure1 code
Proc2
// beginning of Procedure2 code

Call to EndEvent procedure
// end of Proc2 code
// end of Proc1 code
// end of button click code
Execution of EndEvent procedure
// -------------------
// callback case
// -------------------
Click of button
Proc1
Proc2
use of fListFile
Callback1 procedure
// beginning of code of Callback1 Procedure
CallbackProc2
// beginning of code of Callback2 Procedure
Call to ProcEndEvent
// end of ProcedureCallback2 code
// end of ProcedureCallback1 code
Execution of ProcEndEvent
ProcedureCallback1
// beginning of ProcedureCallback1 code
ProcedureCallback2
// beginning of ProcedureCallback2 code
Call to ProcEndEvent
// end of ProcedureCallback2 code
// end of ProcedureCallback1 code
Execution of ProcEndEvent

Stopping an automatic procedure

To stop an automatic procedure, simply use EndAutomatedProcedure.

Procedure with automatic start of threads

Reminder: In WLanguage, by default, each procedure creates an automatic critical section. Therefore, two threads cannot run the same procedure at the same time.
If a procedure that automatically triggers a thread is called twice:
  • in default mode: the first procedure is run and the second procedure waits for the first one to stop before it is run.
  • in threadCriticalSection mode (defined by ThreadMode), the two threads are triggered at the same time.

Object-Oriented Programming (OOP)

When a procedure automation is defined on a class method for an endless execution by timer, a single call can be done for all instances:
  • if the method automation is configured with "Perform the call only": only one of the class instances will perform the call to the method via the timer.
  • if the method automation is configured with "Start an additional timer": all the class instances will perform the call to the method for the current instance.
If the automation is configured for an endless execution in a thread, all the class instances will perform a call to the method for the current instance.
WEBDEV - Server code

Limitation for WEBDEV

Timers are not available in WEBDEV. The automated processes for repetition and for delayed execution are not available.
Remark: However, the use of a repeated automatic procedure can be configured because a set of procedures (or a class, ...) can be shared between several products.
Related Examples:
The Chrono functions Unit examples (WINDEV): The Chrono functions
[ + ] Using the ChronoXXX functions.
These functions are used to calculate the time passed between the start (ChronoStart) and the end (ChronoEnd).
WD Screen Saver Training (WINDEV): WD Screen Saver
[ + ] This example illustrates the creation of a screen saver with the WLanguage functions.
The following topics are presented in this example:
1/ the periodic call to a procedure ("timers")
2/ the management of Windows events
3/ the system functions (call to Windows APIs)
To use the screen saver:
- Rename the executable (.EXE) to.SCR
- Copy the file to the directory of Windows (Ex: C:\WINDOWS)
- Open the window for the display properties of the desktop
- Choose the "Screen Saver" tab
- Select the screen saver generated by WINDEV
WD Who is locking Training (WINDEV): WD Who is locking
[ + ] This example explains how to notify to the users of a HFSQL database in network "who" is locking an inaccessible record.

The following topics are presented in this example:
1/ management of concurrent accesses
2/ automatic refresh by timer
3/ management of a "system" file to store information about the locks.

Summary of the example supplied with WINDEV:
This example, powered by WINDEV, includes 2 projects:
- WD Who is locking: test application that manages a "client" file in network
- WD Supervisor of locks: management tool used to view the existing locks and to force the unlocking if necessary.
An edit form may have been left opened by a user for quite a long time ; this may interfere with the other users.
The 'Free' button sends a message to the relevant user and asks him to free the record.
The 'Unlock!' button is used to force the unlocking of the record.
Caution: This operation will send a message forcing the closing of the application that performed the lock.
Managing the timers Unit examples (WEBDEV): Managing the timers
[ + ] This example explains how to implement a timer and it allows you to:
- Start a timer
- Run a code whenever the timer is called
- Stop a timer
Managing the timers Unit examples (WINDEV Mobile): Managing the timers
[ + ] Implementing a timer:
- start a timer
- run a code whenever the timer is called
- stop a timer
The alarms Unit examples (WINDEV): The alarms
[ + ] Implementing an alarm to display an alert message in the title bar of the active window (regardless of the application).
The following topics are presented:
1/ The system functions (retrieving the handle of a window)
2/ Triggering a process according to a given frequency (timers)
The Chrono functions Unit examples (WINDEV Mobile): The Chrono functions
[ + ] Using the WLanguage "Chrono" functions.
These functions are used to calculate the time passed between the start (ChronoStart) and the end (ChronoEnd).
Minimum version required
  • Version 10
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 06/23/2023

Send a report | Local help