ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Windows functions / Windows Event functions
  • Differences between the Timer and TimerSys functions
  • Locking or non-locking operations
  • Execution time of procedure
  • Process for calling the timer
  • Process for calling the timer
  • Timer and sibling windows
  • Timer and Thread
  • Timer and Windows service
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
Periodically and automatically calls a WLanguage procedure. Called in the procedure, Timer is used to identify the timer that started the procedure.
The sequence of periodic calls to a procedure is called timer. This periodic call will be stopped by EndTimer.
Tip: In most cases, use TimerSys.
WINDEV The automatic procedures can be used instead of Timer. For more details, see automatic procedures.
Example
// Procedure used to display the time in EDT_TIME1 on a regular basis
PROCEDURE Display_Time()
EDT_Time1 = TimeSys()
 
// Process performed when opening the window or the page
// Display_Time will be automatically called every second
IF Timer("Display_Time", 100, 1) = 0 THEN
Error("Unable to create the timer")
END
Syntax

Starting a procedure periodically Hide the details

<Result> = Timer(<Procedure name> , <Period> [, <Number>])
<Result>: Integer
  • Number of the opened timer (<Number> if this parameter is specified),
  • 0 if the timer was not opened.
<Procedure name>: Character string
Name of WLanguage procedure that will be started periodically.
Remark: If this parameter corresponds to the name of an internal procedure, the name of internal procedure must not be enclosed between quotes.
<Period>: Integer ou Duration
Time (in hundredths of a second) between two calls to the procedure by timer. The period precision depends on the pending system status.
This parameter can be:
  • an integer corresponding to the number of hundredths of a second,
  • a Duration variable,
  • the duration in a readable format (e.g., '1s' or '10cs').
<Number>: Optional integer
Number imposed to the timer. If this parameter is specified, the timer number will be the selected number. If this number corresponds to an existing timer, it will be stopped and replaced by the new timer.
WEBDEV - Browser code This parameter is not available. In this version, no number can be imposed to the timer. If the timer must be stopped through programming before closing the page, the timer number must be stored (<Result> parameter) in order to be used in EndTimer.
WINDEVReports and QueriesUser code (UMC)

Finding out the timer number Hide the details

<Result> = Timer()
<Result>: Integer
Number of the timer that called the current procedure.
Remarks
WINDEVReports and QueriesWindowsUser code (UMC)

Differences between the Timer and TimerSys functions

  • Timer allows you to use a timer managed by WINDEV. In this case, the frequency of the call is calculated from the moment when the call to the timer was performed.
  • TimerSys allows you to use a timer managed by the system. In this case, the frequency of the call is calculated from the end of the procedure execution.
Tip: In most cases, use TimerSys.
Indeed, Timer consumes more resources than TimerSys and it operates only when WINDEV windows are displayed (the timer stops when a message box is displayed).
WINDEVReports and QueriesWindowsUser code (UMC)

Locking or non-locking operations

  • A timer is not locked when opening menus, when opening a window, when opening the windows associated with Warning, Confirm, Error, Info, OKCancel and YesNo.
  • A timer is locked when the windows are moved or resized.
WINDEVReports and QueriesWindowsUser code (UMC)

Execution time of procedure

If the time used to process the procedure called by the timer is greater than the time requested between each call to the procedure, the calls to the timer do not pile up: there will be a single pending call.
WINDEVReports and QueriesWindowsUser code (UMC)

Process for calling the timer

  • Code of the project:
    • If Timer is called in a project code, the timer is associated with the project. The timer is interrupted by EndTimer and when the execution of the application is over. The procedure called by the timer must be:
      • a procedure global to the project:
        Timer("<global procedure>", 1000)
        No parameter can be passed to the procedure called (use global variables).
      • a static method of a class:
        Timer("<class>::<static method>", 1000)
    • If Timer is used in the opening process of project and if no window is opened, the timer will be valid for the entire project. It is in a pending status and it will be automatically triggered as soon as a window is opened or during the calls to Multitask.
  • Code of a window, control or local procedure:
    If Timer is called in the code of a window, one of its controls or local procedures, the timer is associated with the window. The timer is interrupted by EndTimer and when closing the window. The procedure called by the timer must be:
    • a local procedure of the window:
      Timer("<local procedure>", 1000)
      No parameter can be passed to the procedure called (use global variables).
    • a procedure global to the project:
      Timer("<global procedure>", 1000)
      No parameter can be passed to the procedure called (use global variables).
    • a static method of a class:
      Timer("<class>::<static method>", 1000)
  • Code of a static method of a class:
    If Timer is called in a static method of a class, the timer is associated with the class. The timer is interrupted by EndTimer and when the execution of the application is over. The procedure called by the timer must be:
    • a static method of the class:
      Timer("::<static method>", 1000)
    • a static method of another class:
      Timer("<class>::<static method>", 1000)
    • a procedure global to the project:
      Timer("<global procedure>", 1000)
  • Code of an object method:
    If Timer is called in a method of an object, the timer is associated with the object. The timer is interrupted by EndTimer or when freeing the object. The procedure called by the timer must be:
    • a non-static method of the object:
      Timer("<:method>", 1000)
    • a static method of the object class:
      Timer("::<static method>", 1000)
    • a static method of another class:
      Timer("<class>::<method>", 1000)
    • a procedure global to the project:
      Timer("<global procedure>", 1000)
WEBDEV - Browser codeAjax

Process for calling the timer

If Timer is called in the code of a page, one of its controls or browser local procedures, the timer is associated with the page. The timer is interrupted by:
  • EndTimer,
  • the page validation,
  • the replacement of the page by another page in the browser.
The procedure called by the timer must be a browser procedure local to the page: Timer("<local procedure>", 1000)
WINDEVReports and QueriesWindowsUser code (UMC)

Timer and sibling windows

When the same window that manages a timer is opened several times (sibling windows in MDI mode), Timer must be used with no timer number. Therefore, a timer number will be automatically assigned to each window.
WINDEVReports and QueriesWindowsUser code (UMC)

Timer and Thread

A procedure started by Timer or TimerSys from a secondary thread (ThreadExecute) will not be called. Indeed, a secondary thread has no interface (which means no opened window): this secondary thread does not receive the messages from the system (the "message loop") like the main application thread.
WINDEVWindows

Timer and Windows service

To use Timer from a Windows service, this function must be called from a window opened by the service code.
Caution: This solution is not recommended. To repeat a process from a service, we advise you to call this process from the code of the service (the code of the service being run in loop).
Related Examples:
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)
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 (WINDEV Mobile): Managing the timers
[ + ] Implementing a timer:
- start a timer
- run a code whenever the timer is called
- stop a timer
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).
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
Component: wd290vm.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Exemlo de Timer
https://youtu.be/36yxeAZtZlE

http://windevdesenvolvimento.blogspot.com.br/2018/05/dicas-1758-publica-windev-novidade23-9.html

https://groups.google.com/d/forum/amarildowindev

// EXEMPLO

TIMER(MOSTRAR_HORA,5S)

// PROCEDURE

PROCEDORE MOSTRAR_HORA

STC_hora=TimeSys()


De matos
29 May 2018

Last update: 06/22/2023

Send a report | Local help