Link to home
Start Free TrialLog in
Avatar of Scot Sunnergren
Scot SunnergrenFlag for United States of America

asked on

VB.Net Threading Tasks and Session Life

I have what is hopefully just a simple informational question on VB.Net and Threading.

I have an internal site that has a few tasks that have to be run by users but that are longer running. I do not want the user to be sitting watching their progress spinning for sometimes 10 minutes or longer. I have used threading to separate a couple of these tasks and that is all working. My question is what happens if a user starts one of these and then closes their browser? Does the thread continue on the server until it completes? I eventually want to create a separate .aspx that will monitor a status file on SQL Server. The threads created will update that status file and the monitor program will report their completion. But if the user closing their browser kills the thread, this will not be satisfactory...is there a better way?

thanks,
Scot
Avatar of kaufmed
kaufmed
Flag of United States of America image

Does the thread continue on the server until it completes?
Since the thread is running on the server, closing the client (a.k.a. the browser) has no bearing on the lifetime of the thread. The answer to your question is no, the thread will not be terminated by a close of the browser.
When someone closes the browser, the session does not literally expire for a default time of around 20 minutes. When session expires, the OnEnd event fires up. You can write code against this in the global.asax file.


Note  that if your web site


Here it takes 30 minutes...

<configuration>
  <system.web>
    <sessionState 
      mode="InProc"
      cookieless="true"
      timeout="30" />
  </system.web>
</configuration>

Open in new window

Avatar of Scot Sunnergren

ASKER

Just to clarify...

The session expiration and the OnEnd event will not affect any thread created by that session unless I write code to handle it? The thread will continue despite those if I ignore them in the threaded code? What happens to session variables? I know that they are shared between the the user session and the threads created by that session. Are they cleared when the session ends?

I am currently using them in the threaded code to report back to the user but will probably do away with them if I move to the separate monitoring page.

thanks.
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@ kaufmed:  I see you are only 1.1 million points from the Legend status. Do we have a legend in EE yet?
Thank you gentlemen. I will mark accepted but if you have any comment on the effect on the session variables within the started thread, it would be appreciated. Are they cleared or replicated to the thread, retaining their settings...

Thanks for the quick responses!
@ScotSunnergren

There wouldn't be any duplication of the Session. I believe, though, that you will have to pass a reference to your session to the thread. In reading, I don't see that threads can access the Session object without it being passed to them.

@unknown_routine

I'm actually about 91,000,000 points away from attaining "Legend" status. The closest person to date is angelIII.

https://www.experts-exchange.com/community/