public static void Shutdown() { if (Enabled) { telemetrySettings.Save(); // before exit, flush the remaining data telemetryClient.Flush(); // flush is not blocking when not using InMemoryChannel so wait a bit. There is an active issue regarding the need for `Sleep`/`Delay` // which is tracked here: https://github.com/microsoft/ApplicationInsights-dotnet/issues/407 if (WaitAtShutdown) { System.Threading.Tasks.Task.Delay(5000).Wait(); } } }