I have a web server cluster (windows 2008) that collects usage data from clients. The servers all batch the data and send after a certain time or amount of data. The problem is we are using AWS auto-scaling, and the machine can be shut down at any time. I would like to detect a shutdown event and send the usage data to the database before the application is killed. Does anyone know if this is possible?
Asked
Active
Viewed 2,226 times
3 Answers
1
I would say, you can perform these tasks (in code/ yourself) when your server goes back up.
Otherwise look here http://social.technet.microsoft.com/Forums/windowsserver/en-US/bd8ea190-9bf4-4915-8ed9-96ee5d6f336a/when-are-windows-server-20032008-shutdown-scripts-run-in-the-shutdown-process

T.S.
- 18,195
- 11
- 58
- 78
-
The server does not go back up, when they are shutdown they are terminated. I've trying to shut the site down in a batch file as you suggest, but I'm running into timing issues http://stackoverflow.com/questions/17733989/halt-batch-file-until-website-stop-is-complete – JoshNaro Jul 22 '13 at 17:04
-
1Check also this thread. http://stackoverflow.com/questions/101647/how-to-schedule-a-task-to-run-when-shutting-down-windows – T.S. Jul 22 '13 at 17:13
1
You can subscribe to this event and perform your logic before the application is shutdown.
Application.Current.Exit +=DoSomething;

Toan Nguyen
- 11,263
- 5
- 43
- 59
-
Tried that. It works if the website is stopped manually, but not on a Windows shutdown. May need to modify the Windows shutdown policy so that it stops the site during a shutdown, as suggested by T.S.'s link. – JoshNaro Jul 18 '13 at 13:59
0
WebActivator is NuGet package designed to clean up application Start
and Shutdown
registrations.
This will register your MyStaticClass.Start()
and MyStaticClass.Shutdown()
methods:
[assembly: WebActivator.PostApplicationStartMethod(typeof(MyStaticClass), "Start")]
[assembly: WebActivator.ApplicationShutdownMethod(typeof(MyStaticClass), "Shutdown")]

Tony O'Hagan
- 21,638
- 3
- 67
- 78