Link to home
Start Free TrialLog in
Avatar of james henderson
james hendersonFlag for United States of America

asked on

session-based multithreading in asp.net 4.5

I am using vs2012 and .net 4.5.  I would like to know how to implement session-based background worker thread in web application using c# code-behind.  any help appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
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
To do what?
Is it by session or by user?
Avatar of james henderson

ASKER

TheLearnedOne:  I have looked at this code, but have a question about it ... does the background thread that's stored in the session end when the session times out?  What is the lifetime of the background worker?

AlexCode:  I have a continuous polling situation to a web service.  I need to run it in it's own thread because it causes all the code behind to stop if I just make the method async and run it in an update panel based on a timer.  don't really know why that behavior is happening ...
You're using a long-polling technique to call a method that takes a lot of time to process?
It doesn't seem like a good thing even in a separate thread...

This won't solve your heavy process problem but might improve your real-time notification system: http://signalr.net/
There is a note on the Default.aspx page:

Try to open this page in two browsers which use different sessions and then run the operation at the same time.  You will learn that each session has its own Background Worker. It is not shared by all users.

When the session ends, the background worker ends.
Avatar of deanvanrooyen
deanvanrooyen

@AlexCode you read my mind, but @dhenderson12 tred with caution if this is not internal...

@dhenderson12 you need to sort out the async issue, if this is read only output then run a separate service that throws it into a cache - don't bog down the web server that needs to be fast. Try and separate your concerns - how are you unit testing this anyway?