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?
3 Answers
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
2 Comments
You can subscribe to this event and perform your logic before the application is shutdown.
Application.Current.Exit +=DoSomething;
1 Comment
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")]