Hi I’m trying to create a weekly web timer running at app level but struggling badly, I can do the calculations ok (T think) but its the setup of the time itself that’s eluding me.
all the docs seem to show at page level but I can’t seem to translate that to app level.
any pointers or examples especially would be welcome.
Thanks Dave and Greg I have tried the below to no avail.
I have a property set as an app property called wkTimer and set the type as webtimer
in the opening event for the App I have
app.wkTimer= New WebTimer
app.wkTimer.Period=10000
app.wkTimer.Location=WebTimer.Locations.Server
AddHandler app.wkTimer , RunTimer
app.wkTimer.RunMode=WebTimer.RunModes.Single
wkTimer.Enabled=True
I get three errors on compile
The constructor of this class is protected, and can only be called from within this class
app.wkTimer= New WebTimer
And ...
This method doesn't return a value
AddHandler app.wkTimer.action , RunTimer
and ...
WebTimer does not have an event named action
AddHandler app.wkTimer.action , RunTimer
I've tried numerous permutations and added /changed things (to many to mention here) but to no avail
again any help appreciated
@brian_franco
That was not what the OP asked for… he asked for timer not cronjobs. And I didn‘t suggest that the db should check on this, but the webapp itself.
But cron jobs may be an alternative solution. It depends on what the job should do. There is no right or wrong here…
The reason this fails is you’re missing the AddressOf keyword:
AddHandler app.wkTimer.Action, AddressOf RunTimer
BUT I would suggest that you subclass WebTimer anyway if you’re going to go that route and put your code into the Action event there. The reason is that you’re less likely to leak WebTimers because of the AddHandler that way.
add WebTimer to the project (just drag and drop it from Controls’ Library)
change its Super (in Inspector Panel) from WebTimer to Timer
change its name to i.e. MyTimer
add Action event to MyTimer
write Your code inside Action event
then:
in App.Opening write:
var MyRegularTimer as new MyTimer
MyRegularTimer.RunMode=timer.RunModes.Multiple
MyRegularTimer.Period=1000
and You have Your standard desktop timer working at app level of Your web server app.
Suggestion would be to set period to something like every hour and then test date / day of week for Your “once a week execution”. Take care not to execute your code more than once that day.
Thanks for the reply, I created a new project just to implement your suggestion and keeping your naming convention but it seems the action event code is never run.
Learning something new gets harder over time, us ‘old boys’ who are only ever self taught and now knocking of the door of 70 tend to be even slower! but still trying!
Your MyTimer instance goes out of scope (and is thus destroyed) at the end of the App.Opening event. Add a property to the App object called MyRegularTimer with its type set to MyTimer then modify the first line of the App.Opening event to:
MyRegularTimer = new MyTimer
As an aside, and in agreement with @brian_franco , such a long timed operation should probably be implemented as a cronjob, and that requires more work. This implementation will fail you at some point when your server/application reboots on day 6 and your timer then doesn’t fire for 13 days. Based on the intention, this may or may not be acceptable.