Skip to content

Instantly share code, notes, and snippets.

@martinnormark
Created January 11, 2013 08:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinnormark/4508906 to your computer and use it in GitHub Desktop.
Save martinnormark/4508906 to your computer and use it in GitHub Desktop.
Handle Azure Web Role restarts gracefully, by waiting for current requests to complete.
public override void OnStop()
{
Trace.TraceInformation("OnStop called from WebRole");
var rcCounter = new PerformanceCounter("ASP.NET", "Requests Current", "");
while (rcCounter.NextValue() > 0)
{
Trace.TraceInformation("ASP.NET Requests Current = " + rcCounter.NextValue().ToString());
System.Threading.Thread.Sleep(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment