![]() |
Can't get LDTimers to work - Printable Version +- Small Basic Forum (https://litdev.uk/mybb) +-- Forum: Small Basic (https://litdev.uk/mybb/forumdisplay.php?fid=1) +--- Forum: Extensions (https://litdev.uk/mybb/forumdisplay.php?fid=3) +--- Thread: Can't get LDTimers to work (/showthread.php?tid=27) |
Can't get LDTimers to work - jrmrhrb00 - 12-25-2023 LitDev, Here's the code: 'Timer.interval= 10 'Timer.tick=OnTimerTick 'Name=LDTimer.Addtick(OnTimerTick) 'LDTimer.Interval(Name,10) Name=LDTimer.Add() LDTimer.Interval(Name,10) LDTimer.Tick=OnTimerTick Sub OnTimerTick TextWindow.WriteLine("Here") EndSub The first 2 lines are the regular timer. That works, but it has been commented out. The next 2 lines have been commented out and they don't work. The next 3 have not been commented out, but they don't work either. I couldn't find this in the old forum. So, how do you make these work. To me they are setup like the first 2 lines which do work. JR RE: Can't get LDTimers to work - jrmrhrb00 - 12-26-2023 LitDev, I did get this to work by putting in a while program delay loop. Here's the code: 'Name=LDTimer.AddTick("OnTimerTick") 'LDTimer.Interval(Name,0) Name=LDTimer.Add() LDTimer.Interval(Name,0) LDTimer.Tick=OnTimerTick While "True" Program.Delay(0) EndWhile Sub OnTimerTick TextWindow.WriteLine("Here") EndSub Notice there isn't any actual delay, but the program keeps on running. So, originally it doesn't have enough time for the tick event to occur, but with the SB timer it is able to do it. Interesting! JR My question now is does each of the ldtimers run on a separate thread? RE: Can't get LDTimers to work - WhTurner - 12-26-2023 JR, Did you realize the the interval is defined in miliseconds, so the program should print 100 lines per second? I havn't tried this but waht happens when you take an interval of 10000 ? EDIT: I trested the following program, this works: Name=LDTimer.Add() LDTimer.Interval(Name,5000) LDTimer.Tick=OnTimerTick while 0=0 Program.Delay(1000) TextWindow.WriteLine(" in while") EndWhile Sub OnTimerTick TextWindow.WriteLine("Here") EndSub RE: Can't get LDTimers to work - litdev - 12-26-2023 JR, You are right that the LD version takes a little longer to get going - not quite sure why this is, but there is more code due to potentially several timers. A continuous loop isn't needed, since SB stays running when TextWindow is open, so the following also work. Code: Name=LDTimer.Add() or Code: Name=LDTimer.Add() Each timer does use its own thread. The following code trys to show how the different timers can be used. Code: 'Original timer Just saw last post by WHTurner and for the reasons above this also works. Code: Name=LDTimer.Add() RE: Can't get LDTimers to work - jrmrhrb00 - 12-26-2023 LitDev and WHTurner, I appreciate both of your comments. I especially liked the code on how to use multiple timers. Thanks, JR |