PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Overview
  • Simple management of threads
  • Principle
  • WLanguage functions
  • Characteristics of a thread
  • Characteristics of threads
  • Access to the existing elements and HFSQL context
  • Recommendations for the processes performed by the thread
  • Forbidden processes
  • Processes of a WINDEV application
  • Exception process and threads
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
Overview
An application is currently run. This application is run in a main thread.
This application can start a secondary thread at any time: this thread is run in parallel to the application. This thread corresponds to a local or global procedure of the application.
This secondary thread is run in parallel to the main application. All the processes that can be run in background task can be performed in this thread: receiving emails, ...
Note: an efficient thread is a thread that waits for a specific event such as a user action, an incoming phone call or email, ...
Note: From version 19, HFSQL is the new name of HyperFileSQL.
Versions 17 and later
Universal Windows 10 App This feature is now available for the Windows Phone applications.
New in version 17
Universal Windows 10 App This feature is now available for the Windows Phone applications.
Universal Windows 10 App This feature is now available for the Windows Phone applications.
Versions 21 and later
Universal Windows 10 App This feature is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This feature is now available in Universal Windows 10 App mode.
Universal Windows 10 App This feature is now available in Universal Windows 10 App mode.
Simple management of threads

Principle

A secondary thread is created by ThreadExecute.
A secondary thread is automatically stopped when:
  • the procedure corresponding to the thread is ended,
  • the object that created the thread is closed.
To force the stop:
  • of a secondary thread, use ThreadStop.
  • Versions 19 and later
    of the current thread, use ThreadEnd.
    New in version 19
    of the current thread, use ThreadEnd.
    of the current thread, use ThreadEnd.
Caution: If a WLanguage function is currently run when a thread is stopped, the thread will actually stop after the execution of the function.

WLanguage functions

The following functions are used to manage the threads:
Versions 16 and later
ThreadCurrent
New in version 16
ThreadCurrent
ThreadCurrent
Returns the name of the thread currently run.
Versions 19 and later
ThreadEnd
New in version 19
ThreadEnd
ThreadEnd
Ends the execution of the current thread.
Versions 09 and later
ThreadExecute
New in version 09
ThreadExecute
ThreadExecute
Starts the execution of a secondary thread.
Versions 09 and later
ThreadMode
New in version 09
ThreadMode
ThreadMode
Changes the management mode of threads.
Versions 10 and later
ThreadPause
New in version 10
ThreadPause
ThreadPause
Pauses the current thread during the specified duration.
Versions 09 and later
ThreadPriority
New in version 09
ThreadPriority
ThreadPriority
Returns or modifies the priority level of a thread.
Versions 09 and later
ThreadResume
New in version 09
ThreadResume
ThreadResume
Resumes the execution of a thread that was interrupted by ThreadSuspend.
Versions 09 and later
ThreadState
New in version 09
ThreadState
ThreadState
Returns the current status of a thread.
Versions 09 and later
ThreadStop
New in version 09
ThreadStop
ThreadStop
Stops a secondary thread.
Versions 09 and later
ThreadSuspend
New in version 09
ThreadSuspend
ThreadSuspend
Temporarily suspends the execution of the specified thread.
Versions 09 and later
ThreadWait
New in version 09
ThreadWait
ThreadWait
Waits for the end of execution of specified thread.
See Functions for managing threads for more details.
Characteristics of a thread

Characteristics of threads

In WLanguage, a secondary thread can be associated with:
  • a procedure local to the current window,
  • a procedure global to the project,
  • a method of a class,
  • a global method of a class.

Access to the existing elements and HFSQL context

When creating a thread, all the existing declarations, objects, elements are common:
  • to the new secondary thread.
  • to the thread in which the secondary thread was created (the main thread in most cases).
Therefore, these threads can access the variables, procedures, ... All the variables created once a thread is started are accessible in the thread where they have been created.
Similarly, when creating a thread, the HFSQL context is automatically duplicated. Each thread handles a specific HFSQL context. 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.
Example: A filter is created on the Customer file. ThreadExecute is used to create the thread named CTX2. 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.
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). See Assisted management of HFSQL errors for more details.
  • Write operations and assignments in a thread: If write operations or assignments are performed in a thread, the other threads currently run do not share this information. Some inconsistencies may occur.
Example:
Code of Thread 1Code of Thread 2
a=i
a++
i=a
b=i
b++
i=b
These two threads share the variables but they do not manage the access to the common resources. If the thread 1 is run before the thread 2, i will be set to 1 instead of 2.
Note: To share an assignment between several threads, you must use semaphores. See Managing the semaphores in the threads for more details.
Recommendations for the processes performed by the thread

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 "Request for refreshing the display" process of a window run by RequestUpdateUI.

Processes of a WINDEV application

By default, the WINDEV processes (click code of a button for example), the procedures and the methods of classes can only be run by a single thread at a given time.
To allow several threads to run these processes at the same time, you must:
  1. Change the default management mode of threads (ThreadMode).
  2. Manage the critical sections and the semaphores in the code of the application.
Java In Java, the processes (click code of a button for example), the procedures and the methods of classes can be run by several threads at the same time. To prevent several threads from running the same code at the same time, critical sections or semaphores must be added to the code of the application.

Exception process and threads

If a general exception process is set in the project initialization code, it will be triggered if an exception occurs:
  • in the main thread,
  • in a secondary thread started by ThreadExecute.
However, if the secondary thread triggers an exception, it will not be possible to find out its origin with ExceptionInfo in the project code. To find out the origin of an exception in a secondary thread, the exception process must be included in the secondary thread.
Related Examples:
The threads Unit examples (WINDEV Mobile): The threads
[ + ] Using threads in an application:
- run a procedure in thread format
- stop a thread
- run a procedure that expects parameters in thread format
The threads (pool) Unit examples (WINDEV Mobile): The threads (pool)
[ + ] Using threads with the WLanguage functions.
Two main topics are presented in this example:
1/ Run processes started in parallel (threads)
2/ Limit the number of threads in execution at a given time
Reminder: a "thread" is a process started in parallel of the current application (main "thread").
This allows you to run a task in background task for example (backup, ...).
Threads are very useful in the industry: supervisor, applications with real-time process check, and so on
The threads Unit examples (WINDEV): The threads
[ + ] Using threads in an application:
- Run a procedure in thread format
- Stop a thread
- Run a procedure that expects parameters in thread format
The threads (pool) Unit examples (WINDEV): The threads (pool)
[ + ] Using threads:
- Running processes started in parallel
- Limiting the number of threads in execution at a given time
Reminder: A thread is a process running in parallel to the current application (main thread).
This allows you to run a task in background task for example (backup, ...).
Threads are very useful in the industry: supervisor, applications with real-time process check, and so on …
WD Using sockets Training (WINDEV): WD Using sockets
[ + ] This example presents the use of the "Socket" functions of WINDEV in Client/Server.
The following topics are presented in this example:
1/ How to connect to a socket
2/ How to accept a request for connection
3/ How to write or read on a socket
Summary of the example supplied with WINDEV:
This example presents the different functions for socket management supplied with WINDEV. To use this example, a first instance of the example must be started in "server" mode. Then, by specifying the name of the computer that will be used as server and a nickname, you can connect to this application in "client" mode. You now have the ability to send messages to all the connected users. In this example, a thread and a socket are associated with each connection.
WD Video surveillance Complete examples (WINDEV): WD Video surveillance
[ + ] This example explains how to broadcast images coming from a Web camera via a network (Intranet, Internet).
The following topics are presented in this example:
1/ Web Camera control
2/ Using the Socket functions
3/ Using the Thread function
4/ Detecting movements
Summary of the example supplied with WINDEV:
This example is used to broadcast the images captured by a Web Camera via a network (Intranet, Internet)
This application groups the "Diffusion server" part and the "Monitor" part.
It allows you to:
- broadcast the images of the Web Camera
- select a "monitor"
- analyze the image to detect a movement. In this case, the relevant recipients (or "monitors") can be notified
- connect up to 8 different Web Cameras and enable the detection of movements
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment