public async Task WatchForChanges() { // Is watching enabled? if (!_localeOptions.Value.WatchForChanges) { return; } if (_watching == false) { var locales = await _localeProvider.GetLocalesAsync(); if (locales != null) { foreach (var locale in locales) { if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Attempting to watch for changes to locale directory at '{0}'.", locale.Descriptor.DirectoryInfo.FullName); } var watcher = new FileSystemWatcher { Path = @locale.Descriptor.DirectoryInfo.FullName }; watcher.Changed += async(sender, args) => { _localeProvider.Dispose(); await _localeStore.DisposeAsync(); }; watcher.EnableRaisingEvents = true; if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation("Successfully watching for changes to locale directory at '{0}'.", watcher.Path); } } } _watching = true; } }