public void Dispose() { _extensibilityTelemetryCollector?.Dispose(); _extensibilityTelemetryCollector = null; GC.SuppressFinalize(this); }
public NuGetTelemetryProvider() { // NuGet's VS extensibility APIs (should) all use INuGetTelemetryProvider. // Since NuGet's MEF extensibility is MEF, which doesn't participate in VS's // "package" and service extensibility, it's entirely possible for other components // to use NuGet's APIs without NuGetPackage ever being loaded/initialized. // Therefore, we should handle our VS extensibility telemetry without depending on // NuGetPackage.InitializeAsync ever being called. _extensibilityTelemetryCollector = new ExtensibilityTelemetryCollector(); VsShellUtilities.ShutdownToken.Register(() => { // It probably shouldn't be possible for IDispose to be called before this shutdown // token being signalled, but let's practise defensive coding and minimize risk of // issues if both methods are executed in parallel. var collector = _extensibilityTelemetryCollector; if (collector != null) { _extensibilityTelemetryCollector = null; // This isn't a normal, or good, pattern, but Dispose will stop the EventListener. // Normally you shouldn't use a disposed object, but in our case we know the // implementation, so we can call it to get telemetry data. collector.Dispose(); TelemetryEvent telemetryEvent = collector.ToTelemetryEvent(); VSTelemetrySession.Instance.PostEvent(telemetryEvent); } }); }
public ExtensibilityEventListener(ExtensibilityTelemetryCollector collector) { _collector = collector; }