Timer on a Webpage

Hi All!

I’ve got a timer that updates info on a webpage. When I switch to another page, it seems this timer interferes with controls on other pages, like comboboxes (it moves selected combobox items at the same rate as the timer.period.

I tried disabling the timer on the page Close event, which fires but timer stays enabled.

Anybody knows what’s this about? Cheers!

[quote=243453:@Shant Khatcherian]Hi All!

I’ve got a timer that updates info on a webpage. When I switch to another page, it seems this timer interferes with controls on other pages, like comboboxes (it moves selected combobox items at the same rate as the timer.period.

I tried disabling the timer on the page Close event, which fires but timer stays enabled.

Anybody knows what’s this about? Cheers![/quote]

It is a known bug.

You may want to try a server-side timer (NOT a webtimer) instead. Or refactor your code to use events, if that is possible.

A webpage is created under a session class, can an external timer call a method in one of those pages?

The timer instance is part of the page, so of course you can call a method. However, in both WebTimer and Timer Action, you need to use WebSessionContext if you want to have access to the session to show a page or a dialog for instance, or access other session properties, for instance. Note that is the case in sockets events as well.

To be able to show a dialog, I add a property WS to the webpage which I set in the WebPage Open event as WS = Session , and in the timer Action event, I can do :

Dim context As New WebSessionContext(ws) dim d as new modal1 d.show

http://documentation.xojo.com/index.php/WebSessionContext

[quote=243462:@Michel Bujardet]The timer instance is part of the page, so of course you can call a method. However, in both WebTimer and Timer Action, you need to use WebSessionContext if you want to have access to the session to show a page or a dialog for instance, or access other session properties, for instance. Note that is the case in sockets events as well.

Suppose I loop through the sessions and I find that this context belongs to a specific page (by name or title or maybe some better way)… If there’s a specific method on that “dynamic” page, how can I call it from an external timer event? That method refreshes the controls on that page.

For i As Integer = 0 To App.SessionCount - 1
Dim context As New WebSessionContext(App.SessionAtIndex(i))
if context.Session.CurrentPage.Name = “Page_XYZ” then

  ' Call the method on that page...

thanks!

[quote=243468:@Shant Khatcherian]Suppose I loop through the sessions and I find that this context belongs to a specific page (by name or title or maybe some better way)… If there’s a specific method on that “dynamic” page, how can I call it from an external timer event? That method refreshes the controls on that page.

For i As Integer = 0 To App.SessionCount - 1
Dim context As New WebSessionContext(App.SessionAtIndex(i))
if context.Session.CurrentPage.Name = “Page_XYZ” then

’ Call the method on that page…[/quote]

You keep referring to an “external” timer event. What do you mean ? By definition, a timer has to be instanciated. Most often that will be the case on the WebPage, as it is the case for a WebTimer. Or are you referring to a timer instanciated in App ?
What do you want to achieve ?

[quote=243492:@Michel Bujardet]You keep referring to an “external” timer event. What do you mean ? By definition, a timer has to be instanciated. Most often that will be the case on the WebPage, as it is the case for a WebTimer. Or are you referring to a timer instanciated in App ?
What do you want to achieve ?[/quote]

by “external” I mean a standard Timer located in e.g. App, outside a webpage. Since a webtimer causes popup menu issues, how can I periodically update controls on a webpage without a webtimer?

thanks!

[quote=243521:@Shant Khatcherian]by “external” I mean a standard Timer located in e.g. App, outside a webpage. Since a webtimer causes popup menu issues, how can I periodically update controls on a webpage without a webtimer?

thanks![/quote]

Where was the Webtimer before ? Create a class, make its super “Timer”. Then drag it to the same exact place the Webtimer was before. Add the very same code in Action, set period and mode the very same way.

I created a class called CustomTimer with super Timer. Dragged the CustomTimer to the webpage, put code in action event… it works but still while its running, the popupmenus on that page are affected.

But now at least when page is closed, other popupmenus are not affected anymore.

thanks!

If I recall correctly, the main issue with WebTimers and PopupMenus that happened was that the selection was jittering.

Now, I do not see how a Timer could do the same. A server-side timer executes on the host and has nothing to do with the HTML controls or javascript, unless of course some code is added that does.

Have you removed the WebTimer ? Even with no Action event, it exists as JavaScript and will indeed keep interfering.

When you mention updating controls, are you updating the popupmenus ?

If you want to place the timer away from the webpage, you can add the Timer instance in Session as a property, use Addhandler to run a method there, and do something like :

If me.CurrentPage.Name = "XYZ" then //Do your update end if

Be careful, though. CurrentPage will be nil until the page has actually been created.

Yes, the effect is jittering popups…
I’m sure I’ve removed the WebTimer… Popupmenu that is affected is not being updated, it is part of a separate container on that webpage.

If me.CurrentPage.Name = “XYZ” then

//Do your update - Can I call a method that only exists on that page from here?

end if

Does the Webtimer have any other side effects than messing with the popupmenus? If not it might be easier to use it and get rid of Popupmenus…

I am extremely surprised. The issue was discussed at length back in summer 2015 :
https://forum.xojo.com/11878-web-popupmenu-and-timer-problem/0

Reading it again shows it is exactly what you bumped into.

A feedback case was filed : <https://xojo.com/issue/21710> to which I attached a Xojo project demonstrating the issue.

And I did verify at the time that using a Timer INSTEAD of a Webtimer fixed the issue. ANY webtimer will interfere with the WebPopupMenu.

I am positive it solved the issue in the demo project I had created. I suspect you still have a webtimer acting up somewhere.

Sure.

[code][code]If me.CurrentPage.Name = “XYZ” then

me.CurrentPage.mymethod()

end if[/code][/code]

You can perfectly well put this in the Action event of a Session timer.

I’m positive, there is no other Webtimer, and no other timer except the Custom Timer in the whole project… Yet it messes up the popup while running.

However, it happens on Firefox but doesn’t not happen on others (tried Opera and Avast SafeZone). Not sure if that indicates something.

Thanks!

Could you try without any timer and see if it still jitters ?

I suspect somehow your project could have kept some code that does the jitter.

I just checked the project I added to the feedback case with the timer workaround, and the WebPopupMenu is solid as a rock in FireFox.

I narrowed it down, the timer itself firing does not cause the popup to flicker. It’s the last line of code that outputs an MBSChartDirector chart.

pic =c.makeChartPicture
Chart_Image.Picture = pic << This line when commented out the popup issue stops.

Not sure if Christian has an idea why.

Cheers

Maybe you could stop updating the Chart_Image.Picture when the ComboBox has focus ?

I’m trying to use the Timer (instead of WebTimer) by creating a class and dropping this onto my form. The event fires but I can’t access the Session or any of it’s properties (no error is thrown but the code does not continue!). Why is that? Is the thread outside of the context of the Session. The Timer is on my form which is within the Session context.

Is this a bug and is it known?

It is not a bug. Objects events often do not have access to the Session. For instance sockets.

You want to use WebSessionContext.

This is the way I do it. There may be better ones, but it works for me :

  • Add a mySession as WebSession property to the WebPage
  • In WebPage Open, add :
  mySession = Session
  • At the beginning of the timer Action :
Dim context As New WebSessionContext(mySession)

Then you have access to Session from inside the timer Action event.

Thanks Michel.

Also, in answer to earlier queries about the webtimer causing refresh problems, if you stop the timer (set to Timer.ModeOff) before the page closes then this gets around the problem. The way we’ve done this is for anything that causes navigation from a page we first stop the timer and then (ironically), we set off a ModeSingle timer that closes the page and navigates away. That way, Xojo has a chance to refresh the javascript timer to off before closing the page.

Hope that’s useful.