I am trying to optimize my code flow. I’ve tried to use a Timer with a Period of zero in order to run some code once at the next event loop, just like I’d do in a Desktop project. The problem, however, is that during the Timer.Action even, the Session object is not set, breaking my intended operations.
In more detail: Basically, here’s the goal: A WebControlWrapper class of mine has lots of functions that modify the UI state. Instead of each call forcing an update to the rendered HTML, I’d like to do that once, when all functions have been called. With a Desktop App, I’d use a Timer for that, and do the re-rendering of the HTML once. The slight delay is not an issue, and in fact make the program more snappy because it does only one redraw instead of dozen redundant ones.
But the problem I have now is that the redraw function can’t access the Session because it’s nil when called from the Timer’s Action event.
And I cannot simply set the Session from the Timer.Action event either, it seems. I could make the Session object available via my own property/function to my wrapper code, but I wonder if that’s safe.
First of all, use a WebTimer or a WebThread instead of Timer. These two are specifically tied to the sessions they were created in. Keep in mind that WebTimers actually run in the browser, so there is some latency there.
If you decide that you must use raw Timers, you should look into WebSessionContext. That lets you set the current session but should be used sparingly because Session context changes can happen at loop boundaries, just like threads.
I noticed that, and that’s where I saw that it did have lots of repeating statements of setting some elements. And that’s what I’m trying to avoid. Is there a way to filter that JS code before it gets sent to the frontend, somehow?
That’s what I was afraid of. So I’d have to pass the Session context as a parameter and can’t just store that in a global variable (for the time of the Timer event) for all my code to access, if I’d stay with using a regular Timer, right?
Since my code is inside a WebControlWrapper, I cannot simply add the WebTimer control to the Page, because the wrapper control is not a page. So I tried adding the WebTimer dynamically to my control. But that doesn’t work: The Timer never fires its Action event.
How do I attach a WebTimer to a Page from within a WebControl?
I noticed that, and that’s where I saw that it did have lots of repeating statements of setting some elements. And that’s what I’m trying to avoid. Is there a way to filter that JS code before it gets sent to the frontend, somehow?[/quote]
Yeah, well, this is a listbox that supports hierarchical lists, and the changes are all over the place. So, when I add rows and then expand into more rows, this leads to a lot of repetitive actual html renderings. I really need to delay the rendering or I need to change the behavior in a way where the user of the listbox has to say when he’s finished adding data. Either way, it sucks.