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..
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.
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.
AarthiPalani...
Member
61 Points
35 Posts
how to do FileSystemWatcher and Timer in thread
Feb 26, 2013 08:46 AM|LINK
Hi friends,
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....
Aarthi
bmwz9
Participant
1574 Points
242 Posts
Re: how to do FileSystemWatcher and Timer in thread
Feb 26, 2013 09:53 AM|LINK
Take a look at these links may help you
http://www.codeproject.com/Articles/271669/Using-FileSystemWatcher-to-monitor-multiple-direct
http://social.msdn.microsoft.com/Forums/is/vbgeneral/thread/03f4226d-5d46-43f4-a3f9-306743fc4159
http://stackoverflow.com/questions/2716401/monitor-multiple-folders-using-filesystemwatcher
http://stackoverflow.com/questions/449993/vb-net-filesystemwatcher-multiple-change-events
--------------------
MCPD , MCSD
--------------------
Please remember to click “Mark as Answer” on the post(s) which helps you !
WishStar99
Contributor
2842 Points
865 Posts
Re: how to do FileSystemWatcher and Timer in thread
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.
AarthiPalani...
Member
61 Points
35 Posts
Re: how to do FileSystemWatcher and Timer in thread
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.
Aarthi
Paul Linton
Star
13421 Points
2535 Posts
Re: how to do FileSystemWatcher and Timer in thread
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.