So I am doing this:
public MainWindow()
{
InitializeComponent();
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "F:\\Scoreboard Assistant\\output\\";
watcher.Filter = "event.xml";
watcher.NotifyFilter=NotifyFilters.LastWrite;
watcher.Changed += new FileSystemEventHandler(file_Changed);
watcher.EnableRaisingEvents = true;
}
private void file_Changed(object sender, FileSystemEventArgs e)
{
XmlDocument config = new XmlDocument();
config.Load(e.FullPath.ToString());
string text1 = config.SelectSingleNode("event/text1").InnerText;
string text2 = config.SelectSingleNode("event/text2").InnerText;
}
What I am doing is watching for changes to a specific XML file. Then if a change to the file is detected, it will read the XML file and extract variables from it. However, when I run the code, I get the following error:
An unhandled exception of type 'System.IO.IOException' occurred in System.Xml.dll
Additional information: The process cannot access the file 'F:\Scoreboard Assistant\output\event.xml' because it is being used by another process.
How do I fix this?