# Life of a webTimer

**URL:** <https://forum.xojo.com/t/life-of-a-webtimer/63020>\
**Category:** Web\
**Created:** [April 28, 2021, 2:16pm UTC](https://forum.xojo.com/t/life-of-a-webtimer/63020 "2021-04-28T14:16:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jury\_Buono](https://forum.xojo.com/user_avatar/forum.xojo.com/jury_buono/32/3074_2.png) [@Jury\_Buono](https://forum.xojo.com/u/Jury_Buono)\
**Post date:** [April 28, 2021, 2:16pm UTC](https://forum.xojo.com/t/life-of-a-webtimer/63020/1 "2021-04-28T14:16:01Z")

</div>

hi, I would like to understand the life cycle of the activity of a single mode web timer.  
Let me explain, I have a webapp, in one of its web pages a button sets the webtime to single mode and enables it, inside the webTimer calls a function that processes data and updates a db. If the thing is long, the user could close the page … at that point, what is foreseen in the code of the webTimer continues to be executed? and the code present in the function called by the webTime continues to be executed until the end?

---

<div class="post-metadata">

**Author:** ![Lars\_Lehmann](https://forum.xojo.com/user_avatar/forum.xojo.com/lars_lehmann/32/11818_2.png) [@Lars\_Lehmann](https://forum.xojo.com/u/Lars_Lehmann)\
**Post date:** [April 28, 2021, 3:12pm UTC](https://forum.xojo.com/t/life-of-a-webtimer/63020/2 "2021-04-28T15:12:57Z")

</div>

> [@Jury\_Buono](#):
>
> at that point, what is foreseen in the code of the webTimer continues to be executed? and the code present in the function called by the webTime continues to be executed until the end?

did you set the timer mode to “off” in the inspector at design-time?

---

<div class="post-metadata">

**Author:** ![Jury\_Buono](https://forum.xojo.com/user_avatar/forum.xojo.com/jury_buono/32/3074_2.png) [@Jury\_Buono](https://forum.xojo.com/u/Jury_Buono)\
**Post date:** [April 28, 2021, 3:40pm UTC](https://forum.xojo.com/t/life-of-a-webtimer/63020/3 "2021-04-28T15:40:14Z")

</div>

the webTime is set by default with mode = 0. The button sets the webTimer mode to 1, then in the webTimer code a function is called after which, again in the webtime code, the webtimer mode is set back to zero

---

<div class="post-metadata">

**Author:** ![Lars\_Lehmann](https://forum.xojo.com/user_avatar/forum.xojo.com/lars_lehmann/32/11818_2.png) [@Lars\_Lehmann](https://forum.xojo.com/u/Lars_Lehmann)\
**Post date:** [April 28, 2021, 4:05pm UTC](https://forum.xojo.com/t/life-of-a-webtimer/63020/4 "2021-04-28T16:05:53Z")

</div>

can you share us your code or a small test project?

The thing with webtimers is, that they live on the webpage itself. It is a frontend control, which communicates with the server. There’s a lot going on which can fail, due to bad app design, bugs, internetspeed and lag.

I always prefer to use a Timer (not Webtimer). This lives on the server.

You can use it so:

- make a property `thisServerTimer` on your weblayout
- instantiate a `servertimer` in the `open`-event of you webpage with:

```auto
self.thisServerTimer = new Timer 
addhandler thisServerTimer.Action, AddressOf thisServerTimer_Action 
thisServerTimer.Period = 10000 
thisServerTimer.Mode = Timer.ModeSingle

```

this is a completely different workflow, as both timers, webtimer and timer, has nothing to do with each other from their implementation point of view. But it works like a sharm.

---

<div class="post-metadata">

**Author:** ![Arthur\_Couture](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/e9a140/32.png) [@Arthur\_Couture](https://forum.xojo.com/u/Arthur_Couture)\
**Post date:** [April 28, 2021, 5:21pm UTC](https://forum.xojo.com/t/life-of-a-webtimer/63020/5 "2021-04-28T17:21:44Z")

</div>

Have also followed the approach that Lars recommended for several situations.

Just a reminder that Server Side Timers (as opposed to WebTimers) need to use a WebSessionContext to access the Session.

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [April 28, 2021, 6:05pm UTC](https://forum.xojo.com/t/life-of-a-webtimer/63020/6 "2021-04-28T18:05:19Z")

</div>

If the WebTimer is set to Browser and the browser gets closed, the timer will not fire because the trigger was in the page on the browser.
