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.
How do others solve this?