private void TimerEvent(object sender, System.Timers.ElapsedEventArgs args) { if (_isDisposed) { return; } try { var currentModTime = File.GetLastWriteTime(_assemblyPath); if (currentModTime > _lastModTime) { _logger.Information("Detected change of {AssemblyPath}. Reloading", _assemblyPath); _lastModTime = currentModTime; IAnalyzer newAnalyzer = new PluggableAnalyzer(_assemblyPath); IAnalyzer?oldAnalyzer = null; lock (_locker) { if (!_isDisposed) { oldAnalyzer = _currentAnalyzer; _currentAnalyzer = newAnalyzer; } else { newAnalyzer.Dispose(); } } oldAnalyzer?.Dispose(); _logger.Information("Reloaded."); } } catch (Exception exception) { _logger.Error(exception, "Error on hot reloading {AssemblyPath}", _assemblyPath); } finally { lock (_locker) { _timer?.Start(); } } }