Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 3894

Question about threads vs Timers

$
0
0

Hi there.

Two quick questions about threads.
One is a programming question, one is “best practice”.

For the best practice, I want to end a program after a given period of time, using a timer. Works perfectly as I want it to. No issue there. Should I use a thread to do this? Is there an advantage or disadvantage?

For the programming part, I take the code I have in my timer, and after creating a thread, place that code in the thread, as shown below:

// when the timer runs out, which means the screensaver stops, blank the display.
// for this we need a shell script.

var blankTheDisplay as  New Shell

//take the number entered in the screensaverMovieListWindow Textfield1 box *60 (seconds in a minute) * 1000 (to make milliseconds)
// every time it fires add a second (1000 ms)

app.endTheProgram = (10 * 60 * 1000) / 1000

if app.incrementTheSeconds >= app.endTheProgram then
  
  blankTheDisplay.Execute ("pmset displaysleepnow”)
  Quit
  
else
  
  app.incrementTheSeconds = (app.incrementTheSeconds +1) 
  System.DebugLog " The end time in ms is : " + app.endTheProgram.ToString + "The incremented seconds are : " + app.incrementTheSeconds.ToString
  
end if

My system.debug shows it only seems to fire 1 time:

10:50:05 PM : sharableMovie Launched
10:50:33 PM :  The end time in ms is : 600 The incremented seconds are : 1
10:51:03 PM : sharableMovie Ended

Is there something else I have to do?

Regards

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 3894

Trending Articles