TImer Never fires Question

Hi there.

I have an issue where I want a Timer to fire after 60 seconds.
Sounds simple, right?

I launch another program with a shell command, however my timer never fires.

When I launch my program, in the open event, I DISABLE the timer (I want the count to start when a specific button is pushed). and when the button is pushed it is enabled.

I have verified this with breakpoints, but even though the Timer is enabled, it never fires.

Is this because the program I launched is running, and I have to return to MY original program somehow?

Regards

Maybe try using Timer.RunModes with it set to runmodes.off. Then set to to runmode.single on button click. This does the same as the reset method, according to the documentation. Maybe enabled does not “reset” it

You could also look at using Timer.CallLater method

The shell by default blocks your program (and the timer). Run it in asynchronous mode. You’ll get the results in DataAvailable

3 Likes

Hi Tim.

Ok, so I have tried to run in asynchronous mode, and I must be doing something wrong, because I got this from the documentation. I have just changed the variable names for my program:

// now run the shell
var testTheShellCommand As Shell
testTheShellCommand = New Shell
testTheShellCommand.ExecuteMode = Shell.ExecuteModes.Asynchronous
testTheShellCommand.Execute ("/Applications/VLC.app/Contents/MacOS/VLC  /Users/xxxxxxxxxx/Desktop/basicMovieVideos/*.*”)

With system debug, I see my timer counting down, but when I hit the time set, the vlc window doesn’t open.

If I do it like this:

// now run the shell
var testTheShellCommand as New Shell
testTheShellCommand.Execute ("/Applications/VLC.app/Contents/MacOS/VLC  /Users/xxxxxxxxxx/Desktop/basicMovieVideos/*.*”)

In a timer, it works.

I’m confused.

Regards

My guess is that testTheShellCommand is a local variable so it is going out of scope when the shell is asynchronous and killing the shell.

What happens if you use a property instead of a local variable?

2 Likes

Alternate approach: use Folderitem.Open:

dim f as folderitem

f=GetFolderitem("/Applications/VLC.app/Contents/MacOS/VLC")

f.Open("/Users/xxxxxxxxxx/Desktop/basicMovieVideos/*.*")

That should produce the same results as your Shell command.

Almost Eric, but the open for some reason really doesn’t like the wildcards.

Regards

What does it do?

Hi Eric.

It opens VLC fine, however, it can’t interpret the . in the folder as videos.

And I just realized that there are some parameters I pass to allow different VLC capabilities (full screen, muted, etc) that I can’t seem to pass using the GetFolderItem.

But other than those two things, it does open VLC, and if I hardcode a video, works fine.

Regards

I’m confused, too. I thought the problem was that the timer didn’t fire. Now you say that it does? I’m not following your issue.

If you look at the documentation for Folderitem.Open, you can add an array of parameters.

Try putting the /path/to/*.* in single quotes in your parameter string.

Hi All.

Ok, I have it working
 so far
 based on everything I learned from reading and you folks. For someone in the future, hopefully this helps them.

In the graphic interface, the user chooses options they want (fullscreen, loop, no audio, etc)

When the app starts, in the Opening event, the 3 timers I have are disabled

// disable the timer so we can select what we want first
windowNewSequentialMoviePlayerVLC.Timer1.Enabled = FALSE
windowNewSequentialMoviePlayerVLC.TimerCountdownToStart.Enabled = FALSE
windowNewSequentialMoviePlayerVLC.timerEndVLC.Enabled = FALSE

Then they push the button to start the program where my timers are enabled.

// set a variable for the progress bar counter
var counterForStartProgressBar as Integer

// reset the progress counter bar to zero
windowNewSequentialMoviePlayerVLC.progressCountdownBar.Value = 0

// set the timer1 (start time timer) maximum value to what has been chosen
// yes I know that I can
 precompress 60 * 1000 to 60000 to convert the minutes the user
// added to milliseconds, but I prefer to do it this way.  60 seconds in a minute, times 1000 
// to convert it to milliseconds.

windowNewSequentialMoviePlayerVLC.timer1.Period = (windowNewSequentialMoviePlayerVLC.textStartAfterTime.text.toInteger * 60 * 1000)
windowNewSequentialMoviePlayerVLC.timerEndVLC.Period = (windowNewSequentialMoviePlayerVLC.textStartAfterTime.text.ToInteger * 60 * 1000) + (windowNewSequentialMoviePlayerVLC.textPlayForTime.text.ToInteger * 60 * 1000)

// enable the timer and start the show
windowNewSequentialMoviePlayerVLC.Timer1.Enabled = TRUE
windowNewSequentialMoviePlayerVLC.TimerCountdownToStart.Enabled = TRUE
windowNewSequentialMoviePlayerVLC.timerEndVLC.Enabled = TRUE

Timer1, the start time (how long to wait before running the program, etc) I do the following:

// now run the shell
app.testTheShellCommand = New Shell
app.testTheShellCommand.ExecuteMode = Shell.ExecuteModes.Asynchronous

app.testTheShellCommand.Execute ("/Applications/VLC.app/Contents/MacOS/VLC " + app.fullScreenValue + " " + app.randomPlayingOrder + " " + app.loopVideos + " " + app.muteTheAudio + " /Users/xxxxxxxxxx/Desktop/basicMovieVideos/*.*”)

// for testing only
System.DebugLog "app.fullscreen = " + app.fullScreenValue
System.DebugLog "app.randomPlayingOrder = " + app.randomPlayingOrder
System.DebugLog "app.loopVideos = " + app.loopVideos
System.DebugLog "app.muteTheAudio = " + app.muteTheAudio

Note that I took the advice to make the varible to make the run Asynchronous is now a shared property
 as was suggested by Kevin G, and put it into Async mode, as was suggested by Tim Hare

I have a timer (timerCountdownToStart) which gives a graphic representation of how long before the program starts. Without it, the user doesn’t see activity. And I figure it is good idea.

' show a progress bar so the user knows how long until the program starts

var counterForStartProgressBar as Integer

'set the maximum of the progressbar based on what the start time was.
' take the start time value, and multiply by 60

counterForStartProgressBar = (windowNewSequentialMoviePlayerVLC.textStartAfterTime.text.ToInteger * 60)
progressCountdownBar.MaximumValue = counterForStartProgressBar

' see if we have reached value of counterForStartProgressBar... meaning the program should run

if progressCountdownBar.Value < progressCountdownBar.MaximumValue then
  
  'it hasn't reached the max value?  Increment
  progressCountdownBar.Value = progressCountdownBar.Value + 1
  
  'for testing
  System.DebugLog "start ProgressBar value is : " + progressCountdownBar.Value.ToString
  
else
  
  
end if

My third timer (timerEndVLC) is set to terminate the program with a shell command.

var killVLCprogram as New Shell
killVLCprogram.Execute ("pkill VLC”)
'MessageBox "End timer fired”

As of this writing, and I am doing more testing, it seems to be operating the way I like it.

I will probably find other things as I add ‘features’ but so far so good.

Thanks for all of the help provided. Though I do have one question I need explained.
What is DataAvailable and how do I use it?

Once again, thank you for all of your help.

Regards