On Thu, 28 Jan 2010, smu johnson wrote:

Hi,

> Alright, I have no freaking clue how to do this properly.
> I have found that HB_IDLEADD() will keep calling the <function()> you
> specify while it's idle.  Problem is, I need it called by millisecond
> lengths.  This becomes a problem because I don't want to hold up the system
> for 5 seconds, simply to count 5 seconds.  I need the interrupts to happen
> every 5 seconds.
> Despite this problem, I tried to experiment.  I put a timer inside the
> function itself using HB_MILLISECONDS() (hint I got from Viktor S.)  But I
> am probably going at it the wrong way, as it uses 100% CPU, and still causes
> the system to freeze for 5 seconds trying to build up the time to 5
> seconds.  I'm no expert either, so feel free to call me a fool!  I also
> tried the Clipper-Tools MILLISEC() function, which also didn't solve the
> problem of stalling the system for 5 seconds, and still drilled the CPU to
> max the same way my foolish solution did.

The CPU usage is caused by active loop you have in your code.
The function you are using to measure the time is unimportant.

   proc main()
      cls
      hb_idleAdd( {||
                     static s_timer := 0
                     local timer := hb_milliseconds()
                     if timer - s_timer > 1000 // execute once per second
                        s_timer := timer
                        hb_dispoutat( 0, 72, time() )
                     endif
                     return nil
                  } )
      wait
   return

best regards,
Przemek
_______________________________________________
Harbour-users mailing list (attachment size limit: 40KB)
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour-users

Reply via email to