On my site I need to do some CPU-heavy computing once a day. Specifically, I calculate the ADP (Average Draft Position) for each player in my database. The way I currently do this is by time-stamping each ADP calculation, then each time a cheat sheet is opened by a user I check to see if it has been at least a day since the last calculation. If it has been more than 24 hours, I kick-off a new Thread where the ADP calculation occurs and return the user to their sheet.
I contemplated doing the ADP Calculation in a Stored Procedure which could be kicked-off via a Trigger, but the code seemed way too complex to perform there so I opted for C# code. Also, a new Thread seemed to make the most sense because it could potentially take a 30 seconds to a minute (and even longer) to do the calcuations, but I don’t want the user to have to wait for this to complete.
While the ADP calculation seems to work, at some point post-processing I’m losing the HttpContext reference in my BLL. Although the ADP calculation works, an exception always seems to get thrown the next time the HttpContext gets referenced in my BLL.