Last post Jan 17, 2011 10:58 AM by linux
Jan 13, 2011 03:14 AM|dundealing|LINK
in my Global.asax I have a timer and every 24 hours it creates an instance of a class and calls a method to send reminder emails with an attachment. In this method I am getting the current HttpContext and using Server.MapPath to get the path to the attachment,
but it is always null. I guess this is because Application_End has been called between the last user accessing the site and the method being called.
As a workaround I am setting the timer interval to 19 minutes but I would rather not call the method 36 times a day when only once is required.
Is there any way, apart from hard coding the path, to ensure the HttpContext is not null?
Jan 14, 2011 04:26 PM|dr.maqk|LINK
at what event have you written your code ? Application start ? Session ? Where ?
Why is Application_End called ? Does it call every day, does the server gets a restart ?
Why dont you write a server side windows service for this. It woud be more suitable and better configurable using cron expresisons.
Jan 14, 2011 05:41 PM|Smacky311|LINK
I asked practically the same question yesterday:
Jan 17, 2011 03:09 AM|amitpatel.it|LINK
For that scheduling kind of implementation I suggest created window service or create console application and schedule it by winow scheduler.
application end event
"ASP 2.0" "Session Expire Event"
Jan 17, 2011 03:20 AM|nilsan|LINK
In this method I am getting the current HttpContext and using Server.MapPath to get the path to the attachment, but it is always null.
Though people may suggest you to use
HttpContext.Current.Server.MapPath("Uploads")You should try that out, if it doesn't work, you can useHostingEnvironment.MapPath(), which doesn't require HttpContext.Current ;)If you're trying to implement Scheduler in Asp.net application, I would suggest you check out http://www.codeproject.com/KB/aspnet/ASPNETService.aspx article by Omar Al Zabir.If you've already taken reference of that, I would suggest you check out the updated version.http://beckelman.net/post/2008/09/20/Simulate-a-Windows-Service-Using-ASPNET-to-Run-Scheduled-Jobs.aspxAlso check out below linkhttp://www.mikesdotnetting.com/Article/129/Simple-task-Scheduling-using-Global.asaxI hope it helps!! :)
Jan 17, 2011 10:58 AM|linux|LINK
Can you post your code ?