Prevent IIS from starting application before previous instance has been shut down during restart
Sometimes when IIS restarts the app pool it will start a new instance of my application before the previous instance is shut down completely. This causes me alot of problem so i wonder what i can do about it.
The course of action goes something like this. (spanning about 20 seconds)
- Application is running, let's call this instance A.
- Restart initializes
- A new instance is started, let's call this B (Logged by Application_Start)
- Incomming request is processed by instance B, this invalidates all data A has cached.
- Timer on instance A is triggered, assumes its cache is valid and writes something invalid into the persistan开发者_StackOverflow中文版t storage.
- Instance A is shut down (logged by Application_End)
Preferable i would like to disable the above behavior completely, IIS should only allow one instance. If not possible, can i in my code detect if other instances is alread running and then wait for it to quit inside application_start? If not possible, what is the best way to work around this?
Disable overlapped recycling:
"In an overlapped recycling scenario, the process targeted for a recycle continues to process all remaining requests while a replacement worker process is created simultaneously. The new process is started before the old worker process stops, and requests are then directed to the new process. This design prevents delays in service, since the old process continues to accept requests until the new process has initialized successfully, and is instructed to shut down only after the new process is ready to handle requests."
http://msdn.microsoft.com/en-us/library/ms525803(v=vs.90).aspx
精彩评论