microsoft / ApplicationInsights-dotnet-server

Microsoft Application Insights for .NET Web Applications
https://azure.microsoft.com/services/application-insights/
133 stars 67 forks source link

Disposing Configuration does not clean up worker threads #1209

Closed v-alwout closed 5 years ago

v-alwout commented 5 years ago

I have a scenario where I need to keep a C#/.Net program running, but it might need to update the configuration for Application Insights. It does this currently by Initializing a new configuration class, creating a new client with the new configuration, then disposing the old configuration. However, I found that after each configuration change, the old threads for perf and dependency collection were not disposed along with the configuration and so it causes excess threads and telemetry to be sent to Application Insights. Now it's possible there's a better way for me to change the configuration without restarting my program, but I am confused as to why the extra threads are not terminated.

SergeyKanzhelev commented 5 years ago

I believe you'd need to dispose telemetry modules explicitly. Configuration doesn't hold reference on those modules.

v-alwout commented 5 years ago

Thanks, I will try that

v-alwout commented 5 years ago

That seemed to work, thank you again.