Page 2 of 2

Posted: Fri May 26, 2006 5:11 pm
by inc.
As youre going to create a thread you directly could use the API way pointed by Psychopanta and me.

Posted: Fri May 26, 2006 5:43 pm
by Kale
inc. wrote:As youre going to create a thread you directly could use the API way pointed by Psychopanta and me.
Honestly, threads are overkill for such an easy thing as a timer. :wink:

Posted: Fri May 26, 2006 6:36 pm
by inc.
Kale wrote:
inc. wrote:As youre going to create a thread you directly could use the API way pointed by Psychopanta and me.
Honestly, threads are overkill for such an easy thing as a timer. :wink:
I meant: If thinking about a thread approach, do better use the API instead of a thread. (my english = my fault ;) )

Posted: Tue Jan 22, 2008 11:47 am
by dell_jockey
Just found this topic, warming it up a bit:
srod wrote:You'll need to use the debugger to kill the following:

Code: Select all

Global timerquit 

Procedure Timer1(time) ;time is in milliseconds 
  Repeat 
    Delay(time) 
    Debug 1
  Until timerquit=1 
EndProcedure 

;fire the timer every second: 
CreateThread(@timer1(),1000)

Repeat
ForEver
please note that if you model a real app on this, the last REPEAT/FOREVER loop (or any other form of loop for that matter) needs an extra Delay to reduce processor load, as in:

Code: Select all

Global timerquit

Procedure Timer1(time) ;time is in milliseconds
  Repeat
    Delay(time)
    Debug 1
  Until timerquit=1
EndProcedure

;fire the timer every second:
CreateThread(@timer1(),1000)

Repeat
  Delay(1)
ForEver
I find this approach quite useful for a small simulation utility that I'm currently developing. A GUI (primary thread) is used to manipulate a number of global variables. These variables are read by the thread and used to write NMEA-like sentences to an RS232 port with speeds varying between 20 and 60 sentences/sec.

EDIT: I just tested this non-api method on Xubuntu as well. It ran without a single modification. Hurray for a portable cross platform timer solution!

Thanks SRod & TheFool!