473,804 Members | 4,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FileSystemWatch ers and CacheDependency

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
CacheDependenci es in the same location for my System.Web.Cach ing.Cache. When
i set up the file watchers and then create the cache dependency i receive an
Exception (AccessViolatio nError - Attempted to read or write protected
memory). I have included a the stack trace from the exception at the end of
this post. This only occurs when i am creating a large number of file
watchers ( i have found the the for my PC i can only create 48!). The
following is a sample application i built which consistantly throws the
exception( note that when i copy the directory structe from the network drive
to a local drive the function works flawlessly ).

List<FileSystem Watcherwatchers = new List<FileSystem Watcher>();
foreach( string directory in Directory.GetDi rectories(
@"\\itchy\image link\Books\V3Bo oks" ) )
{
FileSystemWatch er watcher = new FileSystemWatch er( directory );
watcher.Deleted += new FileSystemEvent Handler( watcher_Deleted );
watcher.Created += new FileSystemEvent Handler( watcher_Created );
watcher.Renamed += new RenamedEventHan dler( watcher_Renamed );
watcher.Changed += new FileSystemEvent Handler( watcher_Changed );
watcher.EnableR aisingEvents = true;
watchers.Add( watcher );
}
CacheDependency depencency2 = new CacheDependency (
@"\\itchy\image link\Books\V3Bo oks\man.lst" );
Partial Stack Trace:

at System.Web.Unsa feNativeMethods .RaiseFileMonit oringEventlogEv ent(String
eventInfo, String path, String appVirtualPath, Int32 hr)
at System.Web.File ChangesMonitor. CreateFileMonit oringException( Int32 hr,
String path)
at System.Web.DirM onCompletion..c tor(DirectoryMo nitor dirMon, String dir,
Boolean watchSubtree, UInt32 notifyFilter)
at System.Web.Dire ctoryMonitor.St artMonitoring()
at System.Web.Dire ctoryMonitor.St artMonitoringFi le(String file,
FileChangeEvent Handler callback, String alias)
at System.Web.File ChangesMonitor. StartMonitoring Path(String alias,
FileChangeEvent Handler callback, FileAttributesD ata& fad)
at System.Web.Cach ing.CacheDepend ency.Init(Boole an isPublic, String[]
filenamesArg, String[] cachekeysArg, CacheDependency dependency, DateTime
utcStart)
at System.Web.Cach ing.CacheDepend ency..ctor(Stri ng filename, DateTime start)
at System.Web.Cach ing.CacheDepend ency..ctor(Stri ng filename)
at WindowsApplicat ion4.Form1.Load TargetFolder() in
D:\MyProjects\W indowsApplicati on4\WindowsAppl ication4\Form1. cs:line 52
at WindowsApplicat ion4.Program.Ma in() in
D:\MyProjects\W indowsApplicati on4\WindowsAppl ication4\Progra m.cs:line 17
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[] args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile, Evidence
assemblySecurit y, String[] args)
at Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext executionContex t,
ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()

Thanks,
Daniel
Aug 31 '06 #1
2 4318
daniel,

Not really answering your question but I am wondering why you don't just
create one FileSystemWatch er on "\\itchy\imagel ink\Books\V3Boo ks" and set the
IncludeSubdirec tories property?

Another option might be to map a drive to "\\itchy\imagel ink\Books\V3Boo ks"
and then enumerate the directories through the mapped drive.

Michael

"daniel" wrote:
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
CacheDependenci es in the same location for my System.Web.Cach ing.Cache. When
i set up the file watchers and then create the cache dependency i receive an
Exception (AccessViolatio nError - Attempted to read or write protected
memory). I have included a the stack trace from the exception at the end of
this post. This only occurs when i am creating a large number of file
watchers ( i have found the the for my PC i can only create 48!). The
following is a sample application i built which consistantly throws the
exception( note that when i copy the directory structe from the network drive
to a local drive the function works flawlessly ).

List<FileSystem Watcherwatchers = new List<FileSystem Watcher>();
foreach( string directory in Directory.GetDi rectories(
@"\\itchy\image link\Books\V3Bo oks" ) )
{
FileSystemWatch er watcher = new FileSystemWatch er( directory );
watcher.Deleted += new FileSystemEvent Handler( watcher_Deleted );
watcher.Created += new FileSystemEvent Handler( watcher_Created );
watcher.Renamed += new RenamedEventHan dler( watcher_Renamed );
watcher.Changed += new FileSystemEvent Handler( watcher_Changed );
watcher.EnableR aisingEvents = true;
watchers.Add( watcher );
}
CacheDependency depencency2 = new CacheDependency (
@"\\itchy\image link\Books\V3Bo oks\man.lst" );
Partial Stack Trace:

at System.Web.Unsa feNativeMethods .RaiseFileMonit oringEventlogEv ent(String
eventInfo, String path, String appVirtualPath, Int32 hr)
at System.Web.File ChangesMonitor. CreateFileMonit oringException( Int32 hr,
String path)
at System.Web.DirM onCompletion..c tor(DirectoryMo nitor dirMon, String dir,
Boolean watchSubtree, UInt32 notifyFilter)
at System.Web.Dire ctoryMonitor.St artMonitoring()
at System.Web.Dire ctoryMonitor.St artMonitoringFi le(String file,
FileChangeEvent Handler callback, String alias)
at System.Web.File ChangesMonitor. StartMonitoring Path(String alias,
FileChangeEvent Handler callback, FileAttributesD ata& fad)
at System.Web.Cach ing.CacheDepend ency.Init(Boole an isPublic, String[]
filenamesArg, String[] cachekeysArg, CacheDependency dependency, DateTime
utcStart)
at System.Web.Cach ing.CacheDepend ency..ctor(Stri ng filename, DateTime start)
at System.Web.Cach ing.CacheDepend ency..ctor(Stri ng filename)
at WindowsApplicat ion4.Form1.Load TargetFolder() in
D:\MyProjects\W indowsApplicati on4\WindowsAppl ication4\Form1. cs:line 52
at WindowsApplicat ion4.Program.Ma in() in
D:\MyProjects\W indowsApplicati on4\WindowsAppl ication4\Progra m.cs:line 17
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[] args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile, Evidence
assemblySecurit y, String[] args)
at Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext executionContex t,
ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()

Thanks,
Daniel
Sep 1 '06 #2
Michael,

The number of file watchers that causes the crash seems to be completely
intermitant, my example may be a bit overly complex but i hav also tried
having just one file watcher on the network directory and some times it
crashes sometimes it doesn't. It also seems to make no difference whether it
is a mapped network drive or not.

Also, the number of filewatchers differs between locations that i map to..
on some network paths i can create several file watchers before a crash, on
other servers only one...

I have tried a mapping to servers with various operating systems including
windows xp, win 2000 and 2003 all with the same results.

Regards
Daniel

"Michael" wrote:
daniel,

Not really answering your question but I am wondering why you don't just
create one FileSystemWatch er on "\\itchy\imagel ink\Books\V3Boo ks" and set the
IncludeSubdirec tories property?

Another option might be to map a drive to "\\itchy\imagel ink\Books\V3Boo ks"
and then enumerate the directories through the mapped drive.

Michael

"daniel" wrote:
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
CacheDependenci es in the same location for my System.Web.Cach ing.Cache. When
i set up the file watchers and then create the cache dependency i receive an
Exception (AccessViolatio nError - Attempted to read or write protected
memory). I have included a the stack trace from the exception at the end of
this post. This only occurs when i am creating a large number of file
watchers ( i have found the the for my PC i can only create 48!). The
following is a sample application i built which consistantly throws the
exception( note that when i copy the directory structe from the network drive
to a local drive the function works flawlessly ).

List<FileSystem Watcherwatchers = new List<FileSystem Watcher>();
foreach( string directory in Directory.GetDi rectories(
@"\\itchy\image link\Books\V3Bo oks" ) )
{
FileSystemWatch er watcher = new FileSystemWatch er( directory );
watcher.Deleted += new FileSystemEvent Handler( watcher_Deleted );
watcher.Created += new FileSystemEvent Handler( watcher_Created );
watcher.Renamed += new RenamedEventHan dler( watcher_Renamed );
watcher.Changed += new FileSystemEvent Handler( watcher_Changed );
watcher.EnableR aisingEvents = true;
watchers.Add( watcher );
}
CacheDependency depencency2 = new CacheDependency (
@"\\itchy\image link\Books\V3Bo oks\man.lst" );
Partial Stack Trace:

at System.Web.Unsa feNativeMethods .RaiseFileMonit oringEventlogEv ent(String
eventInfo, String path, String appVirtualPath, Int32 hr)
at System.Web.File ChangesMonitor. CreateFileMonit oringException( Int32 hr,
String path)
at System.Web.DirM onCompletion..c tor(DirectoryMo nitor dirMon, String dir,
Boolean watchSubtree, UInt32 notifyFilter)
at System.Web.Dire ctoryMonitor.St artMonitoring()
at System.Web.Dire ctoryMonitor.St artMonitoringFi le(String file,
FileChangeEvent Handler callback, String alias)
at System.Web.File ChangesMonitor. StartMonitoring Path(String alias,
FileChangeEvent Handler callback, FileAttributesD ata& fad)
at System.Web.Cach ing.CacheDepend ency.Init(Boole an isPublic, String[]
filenamesArg, String[] cachekeysArg, CacheDependency dependency, DateTime
utcStart)
at System.Web.Cach ing.CacheDepend ency..ctor(Stri ng filename, DateTime start)
at System.Web.Cach ing.CacheDepend ency..ctor(Stri ng filename)
at WindowsApplicat ion4.Form1.Load TargetFolder() in
D:\MyProjects\W indowsApplicati on4\WindowsAppl ication4\Form1. cs:line 52
at WindowsApplicat ion4.Program.Ma in() in
D:\MyProjects\W indowsApplicati on4\WindowsAppl ication4\Progra m.cs:line 17
at System.AppDomai n.nExecuteAssem bly(Assembly assembly, String[] args)
at System.AppDomai n.ExecuteAssemb ly(String assemblyFile, Evidence
assemblySecurit y, String[] args)
at Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object state)
at System.Threadin g.ExecutionCont ext.Run(Executi onContext executionContex t,
ContextCallback callback, Object state)
at System.Threadin g.ThreadHelper. ThreadStart()

Thanks,
Daniel
Sep 3 '06 #3

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

Similar topics

0
1098
by: Nick | last post by:
I am getting the following error when creating a new CacheDependency object: Failed to start monitoring changes to '\\server\share\dir49' This error happens after 48 successful instantiations of CacheDependency using the same fileserver. I have an ASP.NET application that needs to display filecounts for 300 different directories on my fileserver. I have a loop where I get each directory and determine the number of files. In order to...
4
10876
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...
0
1634
by: Keith | last post by:
Hi. I've developed an ASP.NET web service that uses an xml file to store configuration settings. I'm creating a cache dependency based on the xml file and its schema, like this... XmlDocument doc = new XmlDocument(); { ........ } string filePaths = { filePath, schemaPath }; CacheDependency dep = new CacheDependency(filePaths);
0
1085
by: Brian | last post by:
Hi~ I use ASP.NET (framework 1.1 and windows 2003 server-) Cache works well but it never expires with the CacheDependency object and Expire Time Setting. In Windows XP, as far as I remember, It really Does Works (Code) CacheDependency dep=new CacheDependency(Server.MapPath
0
1166
by: Dave S | last post by:
Hi, I'm trying to use cachedependency to refresh a variable when a config file in the web application changes, but it doesn't seem to work no matter what I do. The code is in the global.asax file on the website and is show below. The delegate function 'refresher' only seems to fire in debug mode. The example below has been simplified because I actually want to retrieve values from the config.xml file when it changes but I need to get...
1
3686
by: Diffident | last post by:
Howdy, How can I set the CacheDependency to an Oracle table? I have come across SqlDependency class for using the CacheDependency to an SQL server table but not Oracle. Any pointers? Thanks!!!
1
1822
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 the component is called by two peers at the same time, two FileSystemWatchers 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...
3
3046
by: TJO | last post by:
My asp.net 1.1 app is loading an xml file into cache so that subsequent calls for the xml file will not be pulled from the file system but from the cache instead. My method for loading the xml does the following: 1) Checks the cache to see if it is there 2) If not in cache load xml file, else pull it from cache 3) Creates new CacheDependency object using the full path of the xml and current datetime
3
1850
by: Dave | last post by:
Using ASP.Net 2.0 on Vista with IIS6, if I set a CacheDependency on a file into a Cache entry that I insert and then delete a subdirectory in the same directory that the file is located in then my dependency is triggered and my cache object is deleted. If I create a directory or delete another file in that same directory then the Cache is not bothered. My CacheDependency specifies the full and proper file name and not just the...
0
9706
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
10577
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
10332
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
10077
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
9150
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...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5521
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...
1
4299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
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.