Background task in Windows applications

From: Charles Melice <mail_at_forthcad.com>
Date: Mon, 11 Sep 2000 19:35:45 +0200

I actually use the next system to manage adaptive background tasks
in a Windows program.

I'm interested to know if somebody have found a better system.

Thanks,
Charles Melice

\ ---- code sample ----

Class FictiveWindowClass

  ...

    0 value nCountIdle \ cpu speed indice - busy evaluation
    0 value nMaxIdleCount \ medium cpu usage evaluation
    0 value nLastIdleTime \ last idle time ...
    0 value hHook \ foreground idle proc hook handle

  ...

    DEFER: OnIdle ( -- ) ... ;

    :NONAME ( -- ret )
        _PARAM_0 HC_ACTION =
        If
            1 +to nCountIdle
            nCountIdle nMaxIdleCount 1+ U>
            If
                GetTickCount nLastIdleTime - 500 U>
                If
                    nCountIdle nMaxIdleCount 1+ 2/ to nMaxIdleCount
                    GetTickCount to nLastIdleTime

                    \ --------------------------------------------
                    \ call virtual OnIdle for all running Windows
                    \ * next line to replace by your own code *
                    \ --------------------------------------------
                    hwndmap GetCount 0 ?Do i hwnd[] OnIdle Loop

                    0 to nCountIdle
                Then
            Then
        Then
        hHook _PARAM_0 WPARAM LPARAM CallNextHookEx
        ; 3 CB: ForegroundIdleProc

    \ the only one idle manager

    : ClearIdleManager ( -- )
        hHook ?dup -Exit UnhookWindowsHookEx drop
        0 to hHook ;

    : SetIdleManager ( -- )
        hHook ?Exit
        \
        WH_FOREGROUNDIDLE \ hook type
        ForegroundIdleProc \ hook proc
        HINST
        GetCurrentThreadId
        SetWindowsHookEx to hHook ;

  ...

End

\\ eof
Received on Mon Sep 11 2000 - 10:41:18 PDT


Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!

This archive was generated 07-Feb-2012. Archive updated nightly.