private void ParseSchemaFile(string schemaFilename) { if (!string.IsNullOrWhiteSpace(schemaFilename) && File.Exists(schemaFilename)) { // Make sure the following logic is only run once at any time lock (_parseLock) { // Check for an existing schema file entry under a different path. string currentPath; if (!_filenameToPath.TryGetValue(Path.GetFileName(schemaFilename), out currentPath)) { currentPath = schemaFilename; } SchemaParser parser; if (_schemaFileParsers.TryGetValue(currentPath, out parser)) { if (currentPath != schemaFilename) { _schemaFileParsers.TryRemove(currentPath, out parser); QueueParserWorker(schemaFilename); } else { CurrentParser = parser; } } else { QueueParserWorker(schemaFilename); } } } }
private void QueueParserWorker(string schemaFilename) { CurrentParser = null; _schemaFileParsers.AddOrUpdate(schemaFilename, CurrentParser, (x, y) => null); _filenameToPath.AddOrUpdate(Path.GetFileName(schemaFilename), schemaFilename, (x, y) => schemaFilename); // Start a new task that parses the schema file and sets the current parser (and adds it to the dictionary) ThreadPool.QueueUserWorkItem((x) => { var newParser = new SchemaParser(schemaFilename); newParser.Parse(); _schemaFileParsers.AddOrUpdate(schemaFilename, newParser, (z, y) => newParser); CurrentParser = newParser; }); }