/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (disposing) { _tmrHouseKeeping.Elapsed -= (s, e) => DoHouseKeeping(); _tmrProcessFile.Elapsed -= (s, e) => ProcessDroppedFileHelper(); _configFileMonitor.Changed -= (s, e) => ReloadAndApplyConfigChanges(); _mainWatcher.Changed -= (s, e) => ProcessDroppedJarFile(s, e); _messenger.Notify -= MessengerNotification; _components?.Dispose(); _configFileMonitor.EnableRaisingEvents = false; _configFileMonitor?.Dispose(); _mainWatcher.EnableRaisingEvents = false; _mainWatcher?.Dispose(); _perfCounters?.Dispose(); _jniBridgeManager?.Dispose(); _protectMutex?.Dispose(); _tmrHouseKeeping?.Dispose(); _tmrProcessFile?.Dispose(); // Let's dispose of service hosts (if any) var hosts = HostManager?.DynamicHosts?.ToList(); hosts?.ForEach(_ => _.Value?.Close()); } base.Dispose(disposing); }