I'm using Filesystemwatcher to pick up a file, convert this to UTF-8 and transfer this to the destination. Now what I want to achieve is I need to delay the xml being written to the destination. i.e. by a mere 15-20secs. I know I can use the following here:
System.Threading.Thread.Sleep(milliseconds);
But if I do this, it would delay the thread completely won't it. What would happen to the filesystemwatcher, would it stop picking up the files. My aim is to delay but don't miss any files that would be changed in the source folder. Here is how I'm doing it for the moment:
var doc = new XmlDocument();
doc.Load(FileName);
XmlWriterSettings settings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true };
using (var writer = XmlWriter.Create(destinationFile, settings))
{
System.Threading.Thread.Sleep(15000);
doc.Save(writer);
}
This would stop the thread and delay writing to the xml file which is what I want. But what would happen to the file system watcher then, will it stop as well - as it's part of the same thread.