Aaron Ballman - Thread Pool in Web App ?

Has anyone manged to integrate Aaron Ballman - Thread Pool into a web app? I have purchased the book and read through it but I am not sure if it would blow up in a web app as I dont understand how it would deal with multi sessions of web users. So I guess in an ideal world it would need to some how be able to attach to a session so that you end up with a Thread Pool for each session. Is this even possible? Has anyone done it?

Why would you need a thread pool per user in a WebApplication !?

I’ve already used threads to do things such as sending newsletters to all subscribed recipients, or to backup some files, etc… but this was useful at the application level. I’m not sure what would justify an all ‘thread pool’ per Session. But this is surely possible.

Its the concept that you can pop things into the pool and have it all manged for you by the Manager. My thought was that the way it is designed I was thinking that you the thread may be running at the web application level rather than per session so if you do things on a per user basis then the threads could fire against the wrong session. I may be totally misunderstand how the pool works which is why I posted the question. :wink:

The Pool manages a (usually) fixed amount of Threads as receiver for some Tasks, but it does not manage what you do inside the threads. It is useful when you have a lot of tasks that have to be executed, usually a lot more tasks than available threads.

I’m not sure what would justify this in a Xojo WebApplication but… who knows.

Regarding accessing Sessions from a Thread, this is not a problem, you can easily scan the Sessions and do what you want on those. This is interesting when realtime messaging get involved between the currently connected users on you site. But even this, imho, doesn’t justify a thread pool.

Ok, thanks, I will put this to one side and carry on the way I was going with normal threads. Thanks, saved me lots of wasted time.

Thread.Run never has the Session context set for you like a session/page/control event (if that’s what you’re asking). You have to setup a WebSessionContext before performing actions which manipulate a session’s UI from a thread.

But is a thread run for the specific session? What I mean is if I have a thread in my web project on a page that updates properties created in a module will the properties be set for that session or across the whole app? I want them to be set just for that session only and not effect what other sessions are doing.

Properties in a Module are global and shared between sessions. Property in a Session or WebPage are unique to that session.

Whoa! - So, if I have a recordset property in a Module (call it GlobalRS) and one user (User1) launches the web app and during that session GlobalRS is assigned, then, while User1 session is still active, User2 logs in - completely unrelated to User1, are you saying that my webapp, in User2’s session can access GlobalRS and get the info in that recordset from User1’s session?!?

Ouch - that is scary - I just tested it and you are right. I will move my properties to the session instead of the module they are currently in.

And make sure you open a separate database connection for each session. If you are using SQLite, make sure you set the Multiuser property to True.