I have an ASP.NET website with ASPX pages and ASMX web-services. I want to perform a server side clean-up operation which can be relatively time-consuming (deleting temporary files). For reasons I won’t go into, it is important that no requests (ASPX or ASMX) are processed whilst this operation is in progress.
Ideally I’d like to perform this when there are no requests. What is the best way to do this? I’m thinking of one of the following:
- Determine when there are no requests, then start the operation but stop the operation as soon as a request is received. Is this even possible? Can anyone suggest a mechanism for this?
- Perform the operation each time the ASPNET worker process recycles. If so is there an event for this? Does Application_Start get called each time ASPNET worker process recycles?
- Schedule this operation routinely (e.g once a day) and suspend all requests during this period. Is there a way to automate suspending requests whilst my operation is in progress?
Additional:
I expect the operation should be performed once per day and will take up to one minute. I want to build this into my application so it is fully automated. The files are on the web server. I have full access to the webserver.