My environment – C# 3.5 and ASP.NET 4.0 and VS 2010
Apologies – am a bit new to some of the concepts related to threading and Async methods.
My scenario is this:
- My site will periodically make a couple of GET/POSTS to an external site and collect some data
- This data will be cached in a central cache
- The periodic action will happen once in about 5 minutes, and will happen for every new member who registers on my site. The querying for the member will stop based on certain conditions
- The user does NOT need to be logged in for these periodic queries – they register on the site, and then off my async code goes – it keeps working 24/7 and messages the user once a while via email depending on certain trigger condition. So essentially it all should happen in the background regardless of whether the user is explicitly logged in or not.
Load Expected – I anticipate about 100 total running members a day (accounting for new members + old ones leaving/stopping).
the equation is ~ 100 visitors / day x 4 POST per fetch x 12 fetches / hour x 8 hours / day
In my mind – I’m running 100 threads a day, and each ‘thread’ wakes up once in 5 minutes and does some stuff. The threads will interact with a static central cache which is shared among all of them.
I’ve read some discussions on ThreadPools, AsyncPage etc – all a bit new territory. In my scenario what would you suggest? What’s the best approach to doing this so it’s efficient?
In your response I would appreciate if you mention specific classes/methods/links to use so I can chase this. Thanks a bunch!
You will not be able to do it with ASP.net as such, you will not be able to keep the “threads” running with any level of reliability. IIS could decide to restart the appication pool (I.E. the whole process) at any point in time. Really what you would need is some kind of windows service that runs and makes the requests. You could the use
HttpWebRequest.BeginGetResponsemethod to make your calls. This will fire off the relevent delegate when the response comes back and .net will manage the threading.