473,226 Members | 1,463 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,226 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 10820
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: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.