tags:

views:

32

answers:

1

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:

  1. 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?
  2. 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?
  3. 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.

+1  A: 

If you need to disable requests, you could use a flag in session/database to note that the maintenance is under way. Then in your code, you could display an error page when a request comes in while that flag is set. You could even evaluate the request and have a "black list" of urls that cannot be hit while maintenance is underway.

As for kicking it off, if you use the database flag solution, you could use a Sql Server job to do it all, including scheduling it.

Josh