Last post Apr 02, 2013 03:44 AM by Steven Cheng - MSFT
Mar 19, 2013 01:37 AM|ybjnew|LINK
We have a Rank list, which take 5 miniustes to complete.
We cache the list in memcache , but when the cache expires. It will block all the request.
So I want to cache the list and the time in memcache together, and set a long expire time.
every time get the data from memcache, the programme check the cache time, if it is over 1 hours, the programme start a new thread to regenerate the rank list, and then return the old list immediately,
so the task which rebuld the new rank list will not block the request.
the problem is , is it correct starting a new tread in asp.net ? if the new thread be killed when the aspx thread response end.
how to resolve the spread cache lock ??? we use 3 iis servers
Mar 25, 2013 04:16 AM|Kelmen|LINK
my opinion on the long time thread:
should avoid spawning thread in asp.net
if you want to run a long time process, try look into using web service with single-call or fire-and-forget-approach.
where client issue the request, but won't wait for the result
you can design another page suppose to see the result (managed by the web service), but with logic to detect if the process not finished, then prompt user to check back later.
Mar 25, 2013 10:11 PM|ybjnew|LINK
show some code ??
I think web service run in IIS too, so it is the same with running web pages in IIS>
Apr 02, 2013 03:44 AM|Steven Cheng - MSFT|LINK
You can use ASP.NET app's Global.asax class's Application_Start event to create a new timer (System.Threading.Timer) or directly start a background thread to constantly check the memory cached object and refresh it. I've ever used this appraoch and it does
work (make sure you catch all exceptions in the background thread so as not to crash the entire application). However, one problem is that ASP.NET web app hosted in IIS will be shutdown after being idle for some time. Although we can enlarge the idle timeout,
but once the app process shutdown, no code is executed at all (until the next request comes to the application). Another possible approach you can consider is open an httphandler (or page) which will check and refresh the memory cache once it is requested,
then you can create a task scheduler on a client machine and set a daily or hourly based schedule to access that httphandler (you can create a simple console app to do this).