The idle states

The idle states

Read me file for Idle States

Description

The idle state is the state of the harbour virtual machine when it waits for the user input from the keyboard or the mouse. The idle state is entered during Inkey() calls currently. All applications that don’t use Inkey() function call can signal the idle states with the call of hb_idleState() function (or hb_idleState() on C level).

During idle states the virtual machine calls the garbage collector and it can call user defined actions (background tasks). It also releases the CPU time slices for some poor platforms that are not smart enough to detect it automatically.

For defining the background tasks see the hb_idleAdd() and hb_idleDel() functions.

For direct call for background actions see hb_idleState() function.

For signaling the idle state from C code see the hb_idleState() API function.

Seealso

hb_idleAdd(), hb_idleDel()

hb_idleState()

HB_IdleState()

Evaluates a single background task and calls the garbage collector.

Syntax

      HB_IDLESTATE()

Arguments

None

Description

HB_IDLESTATE() requests the garbage collection and executes a single background task defined by the codeblock passed with HB_IDLEADD() function. Every call to this function evaluates a different task in the order of task creation. There are no arguments passed during a codeblock evaluation.

This function can be safely called even if there are no background tasks defined.

Examples

      nTask1 := hb_idleAdd( {|| SayTime() } )
      nTask2 := hb_idleAdd( {|| SaveScreen() } )
      DO WHILE ! bFinished
        bFinished := DOSomethingVeryImportant()
        hb_idleState()
      ENDDO
      cbAction := hb_idleDel( nTask1 )
      hb_idleDel( nTask2 )

Compliance

Harbour extension similar to FT_IAMIDLE() function available in NanForum library.

Platforms

All

Files

src/rtl/idle.c

Seealso

HB_IDLEADD(), HB_IDLEDEL()

hb_idleDel()

HB_IDLEDEL()

Removes the background task from the list of tasks.

Syntax

      HB_IDLEDEL( <nHandle> ) --> <bAction>

Arguments

<nHandle> is the identifier of the task returned by the HB_IDLEADD() function.

Returns

<bAction> NIL if invalid handle is passed or a codeblock that was passed to HB_IDLEADD() function

Description

HB_IDLEDEL() removes the action associated with passed identifier from the list of background tasks. The identifer should be the value returned by the previous call of HB_IDLEADD() function.

If specified task is defined then the codeblock is returned otherwise the NIL value is returned.

Examples

      nTask := hb_idleAdd( {|| SayTime() } )
      Inkey( 10 )
      bAction := hb_idleDel( nTask )

Compliance

Harbour

Platforms

All

Files

src/rtl/idle.c

Seealso

HB_IDLEADD(), HB_IDLESTATE()

hb_idleAdd()

HB_IDLEADD()

Adds the background task.

Syntax

      HB_IDLEADD( <bAction> ) --> nHandle

Arguments

<bAction> is a codeblock that will be executed during idle states. There are no arguments passed to this codeblock during evaluation.

Returns

<nHandle> The handle (an integer value) that identifies the task. This handle can be used for deleting the task.

Description

HB_IDLEADD() adds a passed codeblock to the list of background tasks that will be evaluated during the idle states. There is no limit for the number of tasks.

Examples

      nTask := hb_idleAdd( {|| SayTime() } )

Compliance

Harbour extension similar to FT_ONIDLE() function available in NanForum library.

Platforms

All

Files

src/rtl/idle.c

Seealso

HB_IDLEDEL(), HB_IDLESTATE()