How to prevent task from being interrupted?

Dear Corona Community,

I am relatively new to the Lua language, and have a question about multi-threading that involves timer.performWithDelay. Please find the below example code.

local time = 10\*60 local timeText = display.newText("10:00", display.contentCenterX, display.contentCenterY, native.systemFont, 100) function updateTime() time = time - 1 local minutes = math.floor(time/60) local seconds = time % 60 timeText.text = string.format("%02d:%02d", minutes, seconds) end local countdownTimer = timer.performWithDelay(1000, updateTime, 0)

Above is a simple code where a timer counts down the time from 10 minutes. The remaining time is shown in the center of the screen in white letters. Nothing too special so far…

However, when I add code–such as the following–so that the entire program becomes

local time = 10\*60 local timeText = display.newText("10:00", display.contentCenterX, display.contentCenterY, native.systemFont, 100) function updateTime() time = time - 1 local minutes = math.floor(time/60) local seconds = time % 60 timeText.text = string.format("%02d:%02d", minutes, seconds) end local countdownTimer = timer.performWithDelay(1000, updateTime, 0) while true do print("test") end

all of a sudden, the remaining time is no longer shown! (although the terminal does endlessly print “test”)

How do I successfully show the remaining time without being interrupted, regardless of what else is going on in my program?

Thanks in advance!

I’m surprised your app isn’t crashing with that ‘while true’ line.  What you are doing is creating an endless loop which the program will never break from until it crashes or is manually terminated.  Perhaps you can give a better example of what you are trying to achieve?  Because surely using an endless loop isn’t it…

I’m surprised your app isn’t crashing with that ‘while true’ line.  What you are doing is creating an endless loop which the program will never break from until it crashes or is manually terminated.  Perhaps you can give a better example of what you are trying to achieve?  Because surely using an endless loop isn’t it…