Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 27, 2013 04:00 AM by Paul Linton
Feb 26, 2013 08:46 AM|LINK
I am using windows service to upload the xml data to the data base,for that am using FileSystemWatcher and Timer.i have two folders ,my service have to watch these two folders ,if xml exist it will fetch the xml and load into database,now my scenario is
this folder can be multiple depends on the Appconfig value,if i put the 4 folder my service have to watch all 4,if it is 5 then service have to do the same.
Now am using 2 watcher and two timer for 2 folders,if its multiple what i have to do..all folders may have the chance to fill with data at the same time span..
if data exist in the form of xml at the movement that data have to process without dead lock,this is for the all folders..
please give me some idea....
Feb 26, 2013 09:53 AM|LINK
Take a look at these links may help you
Feb 26, 2013 04:10 PM|LINK
why do you have to use timer? FilesSystemWatcher automatically executes an event when there's a change to the folder.
Feb 27, 2013 02:57 AM|LINK
Thank you for your valuable reply ,we have used timer and watcher because all folder may have a chance to fill with lots of data at the same time so we have used .
my question is how can I create wacher dynamically depends on number of folder in the app config..without dead lock my all folder data have to process at the same time.
Feb 27, 2013 04:00 AM|LINK
foreach (var folder in folders)
var watcher = new FileSystemWatcher(folder.Path);
watcher.Created += a hendler for the create event
watcher.Changed += a handler for the changed event
watcher.Error += a handler for the error condition
watcher.IncludeSubdirectories = true/false as you desire
watcher.EnableRaisingEvents = true;
I don't really unerstand what it is you need help with, but basically you would just loop over each folder you are interested in and create a new FileSystemWatcher.
The problem you will run into is that the event may be triggered when the file is still locked. In the past I have created a process which has a retry mechanism built in so that if some action cannot be done due to the file being locked then the process
will try again later.