473,809 Members | 2,709 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple FileSystemWatch ers, monitoring the same path

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
FileSystemWatch er.WaitForChang ed method). When the component is called by two
peers at the same time, two FileSystemWatch ers are created (one for each
peer). They are both monitoring the same path (but for different files -
using different filters). The following code illustrates the scenario:

using System;
using System.IO;
using System.Threadin g;

class clsMain {
static void Main() {
Thread thread1 = new Thread(new ThreadStart(t1) );
Thread thread2 = new Thread(new ThreadStart(t2) );
thread1.Start() ;
thread2.Start() ;

Console.ReadLin e();
}

static void t1() {
FileSystemWatch er fs1 = new FileSystemWatch er(@"c:\files", "file1");
if (!fs1.WaitForCh anged(System.IO .WatcherChangeT ypes.All, 10000).TimedOut ) {
System.Console. WriteLine("f1 found!");
} else {
System.Console. WriteLine("f1 not found!");
}
}

static void t2() {
System.IO.FileS ystemWatcher fs2 = new
System.IO.FileS ystemWatcher(@" c:\files", "file2");
if (!fs2.WaitForCh anged(System.IO .WatcherChangeT ypes.All, 10000).TimedOut ) {
System.Console. WriteLine("f2 found!");
} else {
System.Console. WriteLine("f2 not found!");
}
}
}

When copying file1 and file2 to the path c:\files (which are monitored by
the two FileSystemWatch ers) only one of them receives a signal, the other one
simply timesout.

Please advice,
Best Regards,
Fredrik Johansson
Nov 22 '05 #1
1 1822
I solved the problem by creating my own FileSystemWatch er (non-derived) and
thus, pulled the contents of a folder every n second.

"Fredrik Johansson" wrote:
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
FileSystemWatch er.WaitForChang ed method). When the component is called by two
peers at the same time, two FileSystemWatch ers are created (one for each
peer). They are both monitoring the same path (but for different files -
using different filters). The following code illustrates the scenario:

using System;
using System.IO;
using System.Threadin g;

class clsMain {
static void Main() {
Thread thread1 = new Thread(new ThreadStart(t1) );
Thread thread2 = new Thread(new ThreadStart(t2) );
thread1.Start() ;
thread2.Start() ;

Console.ReadLin e();
}

static void t1() {
FileSystemWatch er fs1 = new FileSystemWatch er(@"c:\files", "file1");
if (!fs1.WaitForCh anged(System.IO .WatcherChangeT ypes.All, 10000).TimedOut ) {
System.Console. WriteLine("f1 found!");
} else {
System.Console. WriteLine("f1 not found!");
}
}

static void t2() {
System.IO.FileS ystemWatcher fs2 = new
System.IO.FileS ystemWatcher(@" c:\files", "file2");
if (!fs2.WaitForCh anged(System.IO .WatcherChangeT ypes.All, 10000).TimedOut ) {
System.Console. WriteLine("f2 found!");
} else {
System.Console. WriteLine("f2 not found!");
}
}
}

When copying file1 and file2 to the path c:\files (which are monitored by
the two FileSystemWatch ers) only one of them receives a signal, the other one
simply timesout.

Please advice,
Best Regards,
Fredrik Johansson

Nov 23 '05 #2

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

Similar topics

4
10877
by: Ken Madden | last post by:
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...
5
8335
by: zfeld | last post by:
I am serializing an object to XML and writing it to disk. whenever a change to my object occurs I call the save function to re-write to disk (see code below). I am monitoring the directory where this write is being done using a FileSystemWatcher. My problem is that my Watcher.Changed callback is always invoked twice.This is causing me to process the change twice (causing a performance hit). I am filtering to only be notified for...
0
2098
by: Jeff Reed | last post by:
I am experiencing the the problem outlined the below. Unfortunately, I am using WinXP and I not sure if I can apply the solution due to lack of security control Any feed back would be apreciated http://support.microsoft.com/default.aspx?scid=kb;EN-US;31795 FIX: "Failed to Start Monitoring Directory Changes" Error Message When You Browse to an ASP.NET Pag View products that this article applies to This article was previously...
2
4142
by: Greg Allen | last post by:
I know this has been discussed before, and have found some documentation about it on the web. But nothing has fixed my problem. I am running the 1.1 .NET framework, SP1. I have a web application that I would like to place on a remote shared drive on a different computer. I had problems with that, so I simplified it so that I am trying to use a shared drive on the SAME computer. That doesn't work
9
3218
by: Tim D | last post by:
Hi, I originally posted this as a reply to a rather old thread in dotnet.framework.general and didn't get any response. I thought it might be more relevant here; anyone got any ideas? My questions are below... "David Good" wrote: > We have a network running both Win2k and Win2k3 webservers and our web sites > reside on a UNC network share that happens to be a Network Appliance NAS.
1
1864
by: Mika M | last post by:
Hi! I've made FileSystemWatcher application to copy files from one UNC-path (\\server\directory) into another when files appears into source path. I made it using link http://www.developerfusion.co.uk/show/3636/2/ and it's working fine. Now I should make more than one instances of the FileSystemWatcher class to watch several UNC-paths, how to do this in the same application?
2
4319
by: daniel | last post by:
Hi, I am developing an application that requires me to set up file system watchers on directories on a network drive, as well as set up CacheDependencies in the same location for my System.Web.Caching.Cache. When i set up the file watchers and then create the cache dependency i receive an Exception (AccessViolationError - Attempted to read or write protected memory). I have included a the stack trace from the exception at the end of...
35
9369
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 500000 to 3200000 of a file whose size is say 20MB... how do i request a download which starts directly at 500000th byte... thank u cheers
1
2814
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? I want to monitor multiple folders like: c:\windows c:\my docs
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9602
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10639
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7661
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.