Weekly Web Timer

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

You will need to add it as a Property in App as type WebTimer, then in App.Opening define it with something like this:

App.myTimer = New WebTimer
App.myTimer.Period = 1000*60*60*24*7 'weekly
AddHandler App.myTimer.Action, doMyTimerStuff
App.myTimer.Mode = WebTimer.Modes.Multiple

Please excuse any mistakes, I’m going off memory.

You should just Use a Timer instead of a WebTimer for this. If you use a WebTimer, you must set the Location property to WebTimer.Locations.Server.

1 Like

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

I believe @Greg_O suggested a Timer instead of WebTimer?

1 Like

There is a strange illness: people ask questions, read answers and do as they will (do not follow advices).

True :grin: but learning something new can be difficult
@Grant_A
The reason for Timer instead of WebTimer is that Timer will always run on server

HTH

You should take into account that with so long intervals a service restart may occur. Some people here recommend to restart the WebApps regularly.

I would store the time to run in a database and let a timer run every minute or so to check if it should execute the task.

So you can implement several long running tasks in the future.

1 Like

@Daniel_Fritzsche
Server side Timers (or more like) Server side Cron Jobs are implemented for a reason. No reason for a DB to check on this.

1 Like

@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.

@Daniel_Fritzsche
Understood but sometimes when someone asks for help they do not really know what they are asking for, all replies help

1 Like

There’s another illness Emile… people reply to questions , without answers and do not supply any helpful advice.

1 Like

@Greg O

I tried that previously to run a timer instead of a web times and run into similar issues … my lack of knowledge!

I shall give it another go

Thankyou

I am using timer-based solution and it works:

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.

Hi Pawel

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.

have I missed something, Your thoughts (and anyone else) most welcome.

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! :sleeping: but still trying! :confused:

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.

yep that got it!

Thanks to all helping out. I believe!!! I have the code worked out to reschedule the timer even after a server reboot… No I can progress to trying it.

Once again thanks to all

1 Like