I need a server side timer that starts with App.Open and will manipulate a SQLite database every day at midnight. I added the following to the Event Handler:
Dim Timer1 As New Timer
Timer1.Period = 30000 (30 seconds)
Timer1.Mode = Timer.ModeMultiple
Timer1.Enabled = True
The problem is, how do I create an event handler for the Action event? In a desktop app when you drag a timer control to a page it automatically creates the Action event for you.
What is the uptime like for a cgi app? I see this working in a stand alone app, but a cgi app might get killed off and not be running when the timer should be executing.
I added a new Method called TimerAction with the parameters (sender As Timer) and then put the AddHandler statement in App.Open as Bob suggested. It compiles but the Timer doesn’t seem to fire. I have the Method set to send me a test email but I never get it. Am I missing something?
Here is the App.Open code:
dim Timer1 As new Timer
AddHandler Timer1.Action, AddressOf TimerAction
Timer1.Period=30000
Timer1.Mode = Timer.ModeMultiple
Timer1.Enabled=True
Timer1 should be a property on the App object not defined locally. As soon as the open event is done Timer1 goes out of scope and becomes nil thus never firing (unless you just wrote it that way).
Usually cgi apps start and stop all the time. If it needs to be running at midnight you can have a script call the URL at midnight (or close to it). Script is not the right word but the proper term is escaping me at the moment (yay! It’s Friday!).
Just to pick up on this tread again.
I have similar requirement for a web email server that polls a db and if it finds a new record it grabs the data and uses it to create and send an email.
I have a timer that fires every 25 seconds like Phillip uses at 1701 to watch for the cgi file.
Ie if it’s missing the app shuts down.
It’s basically exactly as the above.
My problem is the cgi app closes, and so the timer stops, and so then does the polling.
I have a feeling that a webapp is not the right project type for this server?
Or is their away to make a cgi xojo app stay active?
Greg could explain it better but the trick is to have a reference to a session that keeps it active. So as long as the session is alive the cgi app won’t die.
WebApplication.AutoQuit
Property (As Boolean)
aWebApplication.AutoQuit = newBooleanValue
or
BooleanValue = aWebApplication.AutoQuit
If True, the server will shutdown automatically when all sessions have ended, which is the default for CGI web apps. If False, the server will not shutdown. This is the default for stand alone web apps.
it is an old topic but maybe it will be helpful for someone. In my case I wanted to have some background process importing something from an external MySQL database into Web App Sqlite database regardless there is any session active (import during night).
In short I wanted to be able to add regular timer to (windowless) App part. I did it this way:
added new empty Class to the project
set its Super: type to Timer and changed the name to MyTimer. Now it behaves as a timer, you can add “Action” handler to it standard way and so on…
in App part I added new public property called “MyOwnTimer” with type “MyTimer” (the name of the class mentioned in #1 & #2 steps)
in Open event of App I added (example):
if MyOwnTimer = nil then
MyOwnTimer =new MyTimer
MyOwnTimer.Mode = Timer.ModeMultiple
MyOwnTimer.Period=60100045 //action every 45 minutes…
MyOwnTimer.Enabled=true
end if
Hello!!!
I am working with a webapp and also need a timer that works all the time, even if no session has been opened.
I follow Pawel Soltysinski criteria and I created “mytimer” as a class timer.
if app.appTimer = nil then
app.apptimer = new mytimer
app.appTimer.mode = timer.modeMultiple
app.appTimer.period = 1000
addHandler app.apptimer.[b]action[/b], addressOf app.apptimer_Control
app.appTimer.enabled=true
end if
the action event does not show as tab key is pressed and the error is:
Type mismatch error, Expected delegate Delegate(MyTimer), but got delegate Delegate()