I am using a FileSystemWatcher
to detect a file. Once it detects the file, I want to read the contents and store it in a string. But when trying to read the contents I get process already in use.
Here is my code:
var watcher = new FileSystemWatcher(b);
watcher.EnableRaisingEvents = true;
watcher.Path = Path.GetDirectoryName(b + "CMDExec.txt");
watcher.Filter = Path.GetFileName(b + "CMDExec.txt");
watcher.Created += Watcher_Created;
private void Watcher_Created(object sender, FileSystemEventArgs e)
{
string b = Path.GetTempPath();
string text = System.IO.File.ReadAllText(b + "CMDExec.txt");
}