I got a SessionNotAvailableException with Asynchronous communication
webpage1 has a superclass of a URLConnection
i have a button on this page that sends stuff to a server and in the class event on the webpage, I use ConcentReceived to do my stuff like opening another page…
normally it should be into the session context because the class is IN the webpage waiting for an event.
Unfortunately that’s not how this works. The only way a web app knows which session is currently “in context” is based on which thread is running and each session that is currently executing code has its own distinct thread.
Now, things like Timer, TCPSocket, UDPSocket, URLConnection, etc, all fire their asynchronous events on the main thread, that is, not associated with a particular session, regardless of where you place the control.
There are a couple of things you can do about this, but the simplest by far looks like this:
- Subclass URLConnection, add a Private String Property named SessionID and implement a Constructor in which you set this property to Session.Identfier.
- In the ContentReceived event, at the very top, put:
Var ctx as New WebSessionContext(App.SessionWithIdentifier(SessionID))
In that event, you should do the minimal amount of work you can to hand off the data to the session. For best results, I suggest just putting the HTTPStatus and the content into properties and use a WebTimer set to Single to process the data a moment later.
Wow, I just noticed that the original post was 8 months ago. I wonder why that came up as “to be answered”.