473,722 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

file system watcher question

i've got one app that writes large files to a specific directory that
is watched by another app via an instance of the file system watcher
class. my problem is that the second app is notified when files are
created, but the first app hasn't finished writing to it - causing a
"file is already open" error when the second app trys to open the file
for processing. what i need is a "file closed" event to be thrown by
the file system watcher object. any idea how i can get around this
problem? thx.

Nov 16 '05 #1
5 2019
What you could to do is contain the monitor with in a while loop that will
exit when processed once.

Inside this loop have a try catch statement that catches the exception that
is thrown when a locked file is accessed. At this point you could then wait
for a certain amount of time, then try to access the file again, and if this
files, wait again etc... until you have access to the file.

so it may look something like this in the creation event handler:

int secondsToSleep = 5;
bool fileAccessed = false;

while ( !fileAccessed )
{
try
{
//
// try to read the file contents here
//

// successful read
fileAccessed = true;
}
catch ( UnauthorizedAcc essException ex ) // is this the exception
thrown?
{
// could not access the file
System.Threadin g.Thread.Sleep ( secondsToSleep * 1000 );
}

}
"ToddT" <tu********@mar itzSPAM.com> wrote in message
news:s3******** *************** *********@4ax.c om...
i've got one app that writes large files to a specific directory that
is watched by another app via an instance of the file system watcher
class. my problem is that the second app is notified when files are
created, but the first app hasn't finished writing to it - causing a
"file is already open" error when the second app trys to open the file
for processing. what i need is a "file closed" event to be thrown by
the file system watcher object. any idea how i can get around this
problem? thx.

Nov 16 '05 #2
thx for the reply.

yeah, that is pretty much what i am doing. it just feels like a hack.
i wish there was a "close file" event thrown by the fsw...
On Thu, 30 Dec 2004 09:27:17 -0000, "Dan Bass" <danielbass [at]
postmaster [dot] co [dot] uk> wrote:
What you could to do is contain the monitor with in a while loop that will
exit when processed once.

Inside this loop have a try catch statement that catches the exception that
is thrown when a locked file is accessed. At this point you could then wait
for a certain amount of time, then try to access the file again, and if this
files, wait again etc... until you have access to the file.

so it may look something like this in the creation event handler:

int secondsToSleep = 5;
bool fileAccessed = false;

while ( !fileAccessed )
{
try
{
//
// try to read the file contents here
//

// successful read
fileAccessed = true;
}
catch ( UnauthorizedAcc essException ex ) // is this the exception
thrown?
{
// could not access the file
System.Threadin g.Thread.Sleep ( secondsToSleep * 1000 );
}

}
"ToddT" <tu********@mar itzSPAM.com> wrote in message
news:s3******* *************** **********@4ax. com...
i've got one app that writes large files to a specific directory that
is watched by another app via an instance of the file system watcher
class. my problem is that the second app is notified when files are
created, but the first app hasn't finished writing to it - causing a
"file is already open" error when the second app trys to open the file
for processing. what i need is a "file closed" event to be thrown by
the file system watcher object. any idea how i can get around this
problem? thx.


Nov 16 '05 #3
That would be nice. I suppose it's because the purpose behind the file
system watcher is for logging files that have been moved/rename/created, and
not for analysing the file details.

"ToddT" <tu********@mar itzSPAM.com> wrote in message
news:25******** *************** *********@4ax.c om...
thx for the reply.

yeah, that is pretty much what i am doing. it just feels like a hack.
i wish there was a "close file" event thrown by the fsw...
On Thu, 30 Dec 2004 09:27:17 -0000, "Dan Bass" <danielbass [at]
postmaster [dot] co [dot] uk> wrote:
What you could to do is contain the monitor with in a while loop that will
exit when processed once.

Inside this loop have a try catch statement that catches the exception
that
is thrown when a locked file is accessed. At this point you could then
wait
for a certain amount of time, then try to access the file again, and if
this
files, wait again etc... until you have access to the file.

so it may look something like this in the creation event handler:

int secondsToSleep = 5;
bool fileAccessed = false;

while ( !fileAccessed )
{
try
{
//
// try to read the file contents here
//

// successful read
fileAccessed = true;
}
catch ( UnauthorizedAcc essException ex ) // is this the exception
thrown?
{
// could not access the file
System.Threadin g.Thread.Sleep ( secondsToSleep * 1000 );
}

}
"ToddT" <tu********@mar itzSPAM.com> wrote in message
news:s3****** *************** ***********@4ax .com...
i've got one app that writes large files to a specific directory that
is watched by another app via an instance of the file system watcher
class. my problem is that the second app is notified when files are
created, but the first app hasn't finished writing to it - causing a
"file is already open" error when the second app trys to open the file
for processing. what i need is a "file closed" event to be thrown by
the file system watcher object. any idea how i can get around this
problem? thx.

Nov 16 '05 #4
Dax
I came up with the same work around. I too feel like it's a hack. I
eventually dropped the system watcher for my own home grown version. I also
found it a little buggy on Windows Server 2000.

Dax

"ToddT" <tu********@mar itzSPAM.com> wrote in message
news:25******** *************** *********@4ax.c om...
thx for the reply.

yeah, that is pretty much what i am doing. it just feels like a hack.
i wish there was a "close file" event thrown by the fsw...
On Thu, 30 Dec 2004 09:27:17 -0000, "Dan Bass" <danielbass [at]
postmaster [dot] co [dot] uk> wrote:
What you could to do is contain the monitor with in a while loop that will
exit when processed once.

Inside this loop have a try catch statement that catches the exception
that
is thrown when a locked file is accessed. At this point you could then
wait
for a certain amount of time, then try to access the file again, and if
this
files, wait again etc... until you have access to the file.

so it may look something like this in the creation event handler:

int secondsToSleep = 5;
bool fileAccessed = false;

while ( !fileAccessed )
{
try
{
//
// try to read the file contents here
//

// successful read
fileAccessed = true;
}
catch ( UnauthorizedAcc essException ex ) // is this the exception
thrown?
{
// could not access the file
System.Threadin g.Thread.Sleep ( secondsToSleep * 1000 );
}

}
"ToddT" <tu********@mar itzSPAM.com> wrote in message
news:s3****** *************** ***********@4ax .com...
i've got one app that writes large files to a specific directory that
is watched by another app via an instance of the file system watcher
class. my problem is that the second app is notified when files are
created, but the first app hasn't finished writing to it - causing a
"file is already open" error when the second app trys to open the file
for processing. what i need is a "file closed" event to be thrown by
the file system watcher object. any idea how i can get around this
problem? thx.

Nov 16 '05 #5
Yep, I don't used the file system watcher either. I reverted to a clunky
polling system. Hey, it works. ;o)

"Dax" <ac*******@onli ne.nospam> wrote in message
news:eg******** ******@TK2MSFTN GP15.phx.gbl...
I came up with the same work around. I too feel like it's a hack. I
eventually dropped the system watcher for my own home grown version. I also
found it a little buggy on Windows Server 2000.

Dax

"ToddT" <tu********@mar itzSPAM.com> wrote in message
news:25******** *************** *********@4ax.c om...
thx for the reply.

yeah, that is pretty much what i am doing. it just feels like a hack.
i wish there was a "close file" event thrown by the fsw...
On Thu, 30 Dec 2004 09:27:17 -0000, "Dan Bass" <danielbass [at]
postmaster [dot] co [dot] uk> wrote:
What you could to do is contain the monitor with in a while loop that
will
exit when processed once.

Inside this loop have a try catch statement that catches the exception
that
is thrown when a locked file is accessed. At this point you could then
wait
for a certain amount of time, then try to access the file again, and if
this
files, wait again etc... until you have access to the file.

so it may look something like this in the creation event handler:

int secondsToSleep = 5;
bool fileAccessed = false;

while ( !fileAccessed )
{
try
{
//
// try to read the file contents here
//

// successful read
fileAccessed = true;
}
catch ( UnauthorizedAcc essException ex ) // is this the exception
thrown?
{
// could not access the file
System.Threadin g.Thread.Sleep ( secondsToSleep * 1000 );
}

}
"ToddT" <tu********@mar itzSPAM.com> wrote in message
news:s3***** *************** ************@4a x.com...
i've got one app that writes large files to a specific directory that
is watched by another app via an instance of the file system watcher
class. my problem is that the second app is notified when files are
created, but the first app hasn't finished writing to it - causing a
"file is already open" error when the second app trys to open the file
for processing. what i need is a "file closed" event to be thrown by
the file system watcher object. any idea how i can get around this
problem? thx.


Nov 16 '05 #6

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

Similar topics

9
715
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit anyway).... Private Sub LogChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs) If e.ChangeType = WatcherChangeTypes.Created Then
3
4142
by: Ron Vecchi | last post by:
Hi all, Can someone point me in the direction on this one, resources or examples. I am writing a Windows Service to monitor a folder. When I file is modified within the folder or any subfolders it should write the name of the file to a xml file. Then at a specifed time all the files in the xml quene will be backed up on a network share. How would I go about monitoring a folder and all subfolders and detect when
7
4121
by: Allen Anderson | last post by:
I'm trying to figure out a way to catch when a file has been written to a directory. I currently have it where I can catch when the file begins writing, but this isn't helpful as I need to know when its done. Does anyone know the right combination of flags to use to catch when the file has been written and closed? (here is my current code). // member variable FileSystemWatcher watcher = new FileSystemWatcher();
0
2567
by: Jack David | last post by:
I am using the following code to monitor a directory for new files. The problem is that when I add a new file to the directory the code creates two events??? what do I have to do to limit it to only one event?? using System; using System.IO; namespace DirectoryWatcher
2
3308
by: Jack David | last post by:
Using the code below I am able to monitor a single directory for a new file and then kick-off a process to deal with the file. The question is??? How would I modify this code to be able to monitor a couple of different directories and based upon the directory where the new file is created kick-off a process Example: File A in Directory B starts process C
2
1020
by: ToddT | last post by:
i've got one app that writes large files to a specific directory that is watched by another app via an instance of the file system watcher class. my problem is that the second app is notified when files are created, but the first app hasn't finished writing to it - causing a "file is already open" error when the second app trys to open the file for processing. what i need is a "file closed" event to be thrown by the file system watcher...
17
2701
by: spentun | last post by:
How can I moitor file which is executed by user or program in window. I need to write a code to monitor file. When user clicks the file(.exe) or is called by program, the name of file will be return to a program. so, excatly, I need to know the name of the executable file that is executed. originally, I try to windows service + FileSystemWatcher. but, There are just created, renamed, deleted, and changed four events in the...
2
2798
by: TwistedPair | last post by:
All, This is sort of a continuation of a previous post of mine. The code below basically reads a registry key to get a path to a folder and it watches for files created in that folder (only created). It also reads another registry key for another path which is a destination path. When a file shows up, it copies it off. It actually works well . . . For small duty stuff but if for example I were to copy in multiple small files...
6
1692
by: Andy B | last post by:
What would i use to look for changes in a file every minute?
0
8863
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
8739
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
9384
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
9238
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
9088
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
8052
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
6681
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...
1
3207
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
2602
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.