473,320 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Multiple FileSystemWatchers

I want to create multiple fileSystemWatchers in a Windows Service to
constantly watch multiple folders for file creations and then execute
certain code based on these actions. The problem is that these directories
are not part of the same directory so I cannot use the subfolder flag. The
number of folders also has to be dynamic so I cannot simply create a certain
number of FileSystemWatchers with different paths. I am going to pull a
list of paths from an XML config file and create a FilesystemWatcher for
each flag. I tried creating a FilesystemWatcher in a thread thinking that I
could simply iterate through the paths creating an FSW for each path. But
when I do this, the FSW gets created, verified through Event log entries,
but nothing happens when a file is created.

Can anyone point me in the right direction? I cannot find any articles
regarding this. I found one article that really seemed like what I was
trying to do but, of course, the article was no longer available. :(

Thanks,

Ken
Nov 15 '05 #1
4 10830
Hi Ken,

I have a windows service with three FileSystemWatchers and it works fine, I
create them in the thread of the service ( the one I create in the OnStart
method )
I think that there is nothing wrong on create multiple FileSystemWatchers,
you can insert them on a ArrayList with each one watching a particular
directory, remember that it's important to keep a reference to the object
( that's why you add it to a ArrayList ) otherwise it gets GC'ed.

Other than that I cannot think of nothing else to do, please just post back
if you need some code.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ken Madden" <os****@microsoft.com> wrote in message
news:eo*************@TK2MSFTNGP09.phx.gbl...
I want to create multiple fileSystemWatchers in a Windows Service to
constantly watch multiple folders for file creations and then execute
certain code based on these actions. The problem is that these directories are not part of the same directory so I cannot use the subfolder flag. The number of folders also has to be dynamic so I cannot simply create a certain number of FileSystemWatchers with different paths. I am going to pull a
list of paths from an XML config file and create a FilesystemWatcher for
each flag. I tried creating a FilesystemWatcher in a thread thinking that I could simply iterate through the paths creating an FSW for each path. But
when I do this, the FSW gets created, verified through Event log entries,
but nothing happens when a file is created.

Can anyone point me in the right direction? I cannot find any articles
regarding this. I found one article that really seemed like what I was
trying to do but, of course, the article was no longer available. :(

Thanks,

Ken

Nov 15 '05 #2
I would love to see a code sample. The first thing I tried was an array but
was not able to create an array of FileSystemWatchers. That seems like that
would be the ideal way to do it for my purposes.

Thanks,

Ken

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
Hi Ken,

I have a windows service with three FileSystemWatchers and it works fine, I create them in the thread of the service ( the one I create in the OnStart
method )
I think that there is nothing wrong on create multiple FileSystemWatchers,
you can insert them on a ArrayList with each one watching a particular
directory, remember that it's important to keep a reference to the object
( that's why you add it to a ArrayList ) otherwise it gets GC'ed.

Other than that I cannot think of nothing else to do, please just post back if you need some code.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ken Madden" <os****@microsoft.com> wrote in message
news:eo*************@TK2MSFTNGP09.phx.gbl...
I want to create multiple fileSystemWatchers in a Windows Service to
constantly watch multiple folders for file creations and then execute
certain code based on these actions. The problem is that these directories
are not part of the same directory so I cannot use the subfolder flag.

The
number of folders also has to be dynamic so I cannot simply create a

certain
number of FileSystemWatchers with different paths. I am going to pull a
list of paths from an XML config file and create a FilesystemWatcher for
each flag. I tried creating a FilesystemWatcher in a thread thinking that I
could simply iterate through the paths creating an FSW for each path.

But when I do this, the FSW gets created, verified through Event log entries, but nothing happens when a file is created.

Can anyone point me in the right direction? I cannot find any articles
regarding this. I found one article that really seemed like what I was
trying to do but, of course, the article was no longer available. :(

Thanks,

Ken


Nov 15 '05 #3
Hi Ken,

I just assembled the code below, you will need to improve it, it will just
point you in the right direction , I cahnged a file in the inetpub directory
and it worked almost fine, almost fine cause it raise two times the same
event, take a look into it and tell me if you solved your problem, I will
look into that double event thing later this afternoon.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

ArrayList fw= new ArrayList();

protected void CreateWatchers()

{

string [] strs = new string[] {@"c:\temp",@"c:\projects", @"c:\inetpub" };

foreach( string s in strs)

{

FileSystemWatcher Clientwatcher= new FileSystemWatcher();

Clientwatcher.Path = s;

Clientwatcher.Filter = "*.flag";

Clientwatcher.NotifyFilter = NotifyFilters.LastWrite;

Clientwatcher.Created += new FileSystemEventHandler( ClientFileUpdated);

Clientwatcher.Changed += new FileSystemEventHandler( ClientFileUpdated);

Clientwatcher.EnableRaisingEvents =true;

fw.Add( Clientwatcher);

}

}

public void ClientFileUpdated(object source, FileSystemEventArgs e)

{

object o = source;

}
"Ken Madden" <os****@microsoft.com> wrote in message
news:eG**************@tk2msftngp13.phx.gbl...
I would love to see a code sample. The first thing I tried was an array but was not able to create an array of FileSystemWatchers. That seems like that would be the ideal way to do it for my purposes.

Thanks,

Ken

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
Hi Ken,

I have a windows service with three FileSystemWatchers and it works fine,
I
create them in the thread of the service ( the one I create in the OnStart method )
I think that there is nothing wrong on create multiple FileSystemWatchers, you can insert them on a ArrayList with each one watching a particular
directory, remember that it's important to keep a reference to the object ( that's why you add it to a ArrayList ) otherwise it gets GC'ed.

Other than that I cannot think of nothing else to do, please just post

back
if you need some code.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ken Madden" <os****@microsoft.com> wrote in message
news:eo*************@TK2MSFTNGP09.phx.gbl...
I want to create multiple fileSystemWatchers in a Windows Service to
constantly watch multiple folders for file creations and then execute
certain code based on these actions. The problem is that these

directories
are not part of the same directory so I cannot use the subfolder flag.

The
number of folders also has to be dynamic so I cannot simply create a

certain
number of FileSystemWatchers with different paths. I am going to pull a list of paths from an XML config file and create a FilesystemWatcher for each flag. I tried creating a FilesystemWatcher in a thread thinking

that
I
could simply iterate through the paths creating an FSW for each path.

But when I do this, the FSW gets created, verified through Event log entries, but nothing happens when a file is created.

Can anyone point me in the right direction? I cannot find any articles regarding this. I found one article that really seemed like what I was trying to do but, of course, the article was no longer available. :(

Thanks,

Ken



Nov 15 '05 #4
Beautiful. My implementation was slightly off. You put me on the right
track. I got my multiple listeners running off a two path array. Now I can
scale that out to however many paths are stored in my XML config pretty
easily. Thank you thank you. I have been beating my head against the wall.

As far as the double events, that is common when using the changed and
created event captures. If you create a new file in that directory, rather
than just copy one in from somewhere else, a create event is raised when the
file is created. But it is really only creating a placeholder at that point.
then the content is written to the file which raises the changed event. I
had to deal with that on a different utility I wrote a while back. I
basically just worked around it by detecting the create, sleeping for two
minutes, and then processing the xml log file. I am sure this is not ideal
but it worked for that particular application. I have found plenty of docs
on the web regarding this problem but not a lot of soltuions.

Thanks again,

Ken

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:OD**************@tk2msftngp13.phx.gbl...
Hi Ken,

I just assembled the code below, you will need to improve it, it will just point you in the right direction , I cahnged a file in the inetpub directory and it worked almost fine, almost fine cause it raise two times the same
event, take a look into it and tell me if you solved your problem, I will
look into that double event thing later this afternoon.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

ArrayList fw= new ArrayList();

protected void CreateWatchers()

{

string [] strs = new string[] {@"c:\temp",@"c:\projects", @"c:\inetpub" };

foreach( string s in strs)

{

FileSystemWatcher Clientwatcher= new FileSystemWatcher();

Clientwatcher.Path = s;

Clientwatcher.Filter = "*.flag";

Clientwatcher.NotifyFilter = NotifyFilters.LastWrite;

Clientwatcher.Created += new FileSystemEventHandler( ClientFileUpdated);

Clientwatcher.Changed += new FileSystemEventHandler( ClientFileUpdated);

Clientwatcher.EnableRaisingEvents =true;

fw.Add( Clientwatcher);

}

}

public void ClientFileUpdated(object source, FileSystemEventArgs e)

{

object o = source;

}
"Ken Madden" <os****@microsoft.com> wrote in message
news:eG**************@tk2msftngp13.phx.gbl...
I would love to see a code sample. The first thing I tried was an array but
was not able to create an array of FileSystemWatchers. That seems like

that
would be the ideal way to do it for my purposes.

Thanks,

Ken

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
Hi Ken,

I have a windows service with three FileSystemWatchers and it works fine,
I
create them in the thread of the service ( the one I create in the OnStart method )
I think that there is nothing wrong on create multiple FileSystemWatchers, you can insert them on a ArrayList with each one watching a particular
directory, remember that it's important to keep a reference to the object ( that's why you add it to a ArrayList ) otherwise it gets GC'ed.

Other than that I cannot think of nothing else to do, please just post

back
if you need some code.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ken Madden" <os****@microsoft.com> wrote in message
news:eo*************@TK2MSFTNGP09.phx.gbl...
> I want to create multiple fileSystemWatchers in a Windows Service to
> constantly watch multiple folders for file creations and then execute > certain code based on these actions. The problem is that these
directories
> are not part of the same directory so I cannot use the subfolder flag. The
> number of folders also has to be dynamic so I cannot simply create a
certain
> number of FileSystemWatchers with different paths. I am going to pull a
> list of paths from an XML config file and create a FilesystemWatcher for > each flag. I tried creating a FilesystemWatcher in a thread
thinking that
I
> could simply iterate through the paths creating an FSW for each
path. But
> when I do this, the FSW gets created, verified through Event log

entries,
> but nothing happens when a file is created.
>
> Can anyone point me in the right direction? I cannot find any

articles > regarding this. I found one article that really seemed like what I was > trying to do but, of course, the article was no longer available.

:( >
> Thanks,
>
> Ken
>
>



Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rolf Wester | last post by:
Hi, I have a form with a select element with multiple="true". When using the GET method (I suppose the same happens with the POST method) I can seen that the form sends channels=CH1&channels=CH2...
66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
11
by: Ohaya | last post by:
Hi, I'm trying to understand a situation where ASP seems to be "blocking" of "queuing" requests. This is on a Win2K Advanced Server, with IIS5. I've seen some posts (e.g.,...
6
by: Ben Hallert | last post by:
Hi guys, I'm trying to figure out what bone headed mistake I made on something I put together. I've got a form (named 'context') that has a variable number of select-multiple inputs on it. ...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
9
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated...
1
by: Fredrik Johansson | last post by:
Hello, I have built a .NET remoting solution (SingleCall) that writes a file to disk, then waits for a second file in a specified folder (using the FileSystemWatcher.WaitForChanged method). When...
35
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from...
1
by: D2 | last post by:
Hi All, I'm just wondering whether a FileSystemWatcher object can be used to monitor multiple directores or we have to create one FileSystemWatcher object for each folder we need to monitor? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.