I have a windows service to process xml files in the queue. The files in the queue were added by FileSystemWatcher event when files created.
The code is:
namespace XMLFTP { public class XML_Processor : ServiceBase { public string s_folder { get; set; } public XML_Processor(string folder) { s_folder = folder; } Thread worker; FileSystemWatcher watcher; DirectoryInfo my_Folder; public static AutoResetEvent ResetEvent { get; set; } bool running; public bool Start() { my_Folder = new DirectoryInfo(s_folder); bool success = true; running = true; worker = new Thread(new ThreadStart(ServiceLoop)); worker.Start(); // add files to queue by FileSystemWatcher event return (success); } public bool Stop() { try { running = false; watcher.EnableRaisingEvents = false; worker.Join(ServiceSettings.ThreadJoinTimeOut); } catch (Exception ex) { return (false); } return (true); } public void ServiceLoop() { string fileName; while (running) { Thread.Sleep(2000); if (ProcessingQueue.Count > 0) { // process file and write info to DB. } } }
void watcher_Created(object sender, FileSystemEventArgs e)
{case WatcherChangeTypes.Created:// add files to queue
}
It works perfectly, now I want to add other files to the queue. These files are not triggered by FileSystemWatcher. There is a code to do it.
DetectXML(my_Folder); // add other files to the queue
There files will be also processed by the service ServiceLoop method. My question is where should I place the code DetectXML(my_Folder)?
Before worker.Start() that is
my_Folder = new DirectoryInfo(s_folder); DetectXML(my_Folder); bool success = true; running = true; worker = new Thread(new ThreadStart(ServiceLoop)); worker.Start();
Or after worker.Start(), which is likely
my_Folder = new DirectoryInfo(s_folder); bool success = true; running = true; worker = new Thread(new ThreadStart(ServiceLoop)); worker.Start(); DetectXML(my_Folder);Or it doesn't matter at all. Thank you.