AzureWebFarm.Helpers.DiagnosticsHelper.WaitForAllHttpRequestsToEnd C# (CSharp) Method

WaitForAllHttpRequestsToEnd() public static method

public static WaitForAllHttpRequestsToEnd ( ILogger logger ) : void
logger ILogger
return void
        public static void WaitForAllHttpRequestsToEnd(ILogger logger)
        {
            // http://blogs.msdn.com/b/windowsazure/archive/2013/01/14/the-right-way-to-handle-azure-onstop-events.aspx
            var pcrc = new PerformanceCounter("ASP.NET", "Requests Current", "");
            while (true)
            {
                var rc = pcrc.NextValue();
                logger.InfoFormat("ASP.NET Requests Current = {0}, {1}.", rc, rc <= 0 ? "permitting role exit" : "blocking role exit");
                if (rc <= 0)
                    break;
                Thread.Sleep(TimeSpan.FromSeconds(1));
            }
        }