xHarbour Reference Documentation > Function Reference |
Adds a background task for being executed during idle states.
HB_IdleAdd( <bAction> ) --> nTaskHandle
The function returns a numeric task handle that must be preserved for other idle processing functions, such as HB_IdleDel().
Function HB_IdleAdd() adds the passed codeblock to the list of background tasks that will be executed when the main program enters an idle state. There is no limit for the number of idle tasks.
The idle state is the state of the xHarbour virtual machine (VM) when it waits for user input from the keyboard or the mouse. The VM enters idle state during Inkey() calls. All applications that do not use Inkey() function calls can signal the idle state with a call to the HB_IdleState() function.
Note: tasks for regular background processing are created with function HB_BackGroundAdd().
An alternative for background tasks is provided with threads. Refer to function StartThread() for running parts of an application simultaneously in multiple threads.
See also: | HB_BackGroundAdd(), HB_IdleDel(), HB_IdleState(), HB_IdleSleepMSec(), StartThread() |
Category: | Background processing , xHarbour extensions |
Source: | rtl\idle.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// This example halts the program for 10 seconds with the Inkey() // function. A message is continuously displayed until either // a key is pressed or 10 seconds have elapsed. PROCEDURE Main LOCAL nCounter := 10 CLS DispOutAtSetPos( .F. ) nTask := HB_IdleAdd( {|| DispMsg( --nCounter ) } ) ? "Test program for idle state" ? ? InKey( 10 ) HB_IdleDel( nTask ) ? ? "Program resumes" RETURN PROCEDURE DispMsg( nCounter ) LOCAL cMsg cMsg := "Program resumes in " cMsg += Ltrim( Str(nCounter) ) cMsg += " seconds unless you press a key" DispoutAt( Row(), Col(), cMsg ) Hb_IdleSleep( 1 ) RETURN
http://www.xHarbour.com