473,382 Members | 1,369 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,382 software developers and data experts.

I'm trying to use FileSystemWatcher

Hi,

I'm trying to use FileSystemWatcher to determine when a new file has been
added to a directory. However, after the file has been added, I need to
process the file. This results in a problem if the file is large and takes
time to copy, as the events appear to get received before the copy is
finished.
I've tried listening to the Created event, as well as the Changed event
(which gets fired multiple times) based on the last write time. When
listening to the event, I try checking if I can open the file for exclusive
access to determine if the copy operation is completed, but this still
doesn't seem to work all the time.
Any ideas would be greatly appreciated.
Thanks,

Nov 28 '06 #1
4 4696
Hi,

Have you tried setting the EnableRaisingEvents property of the
FileSystemWatcher to false when you start processing and then set it back to
true when you're done?

Joe
--
http://www.csharp-station.com
"somequestion" wrote:
Hi,

I'm trying to use FileSystemWatcher to determine when a new file has been
added to a directory. However, after the file has been added, I need to
process the file. This results in a problem if the file is large and takes
time to copy, as the events appear to get received before the copy is
finished.
I've tried listening to the Created event, as well as the Changed event
(which gets fired multiple times) based on the last write time. When
listening to the event, I try checking if I can open the file for exclusive
access to determine if the copy operation is completed, but this still
doesn't seem to work all the time.
Any ideas would be greatly appreciated.
Thanks,

Nov 28 '06 #2
of course, i used EnableRaisingEvents property ...
but it is nothing to do with this property
if i can know about file copy process is finished ?
after that i just invoke Create Event..it will work ...
how can i know the way about checking file copy has finished...

"Joe Mayo (C# MVP)" <Jo*********@discussions.microsoft.comwrote in message
news:99**********************************@microsof t.com...
Hi,

Have you tried setting the EnableRaisingEvents property of the
FileSystemWatcher to false when you start processing and then set it back
to
true when you're done?

Joe
--
http://www.csharp-station.com
"somequestion" wrote:
>Hi,

I'm trying to use FileSystemWatcher to determine when a new file has been
added to a directory. However, after the file has been added, I need to
process the file. This results in a problem if the file is large and
takes
time to copy, as the events appear to get received before the copy is
finished.
I've tried listening to the Created event, as well as the Changed event
(which gets fired multiple times) based on the last write time. When
listening to the event, I try checking if I can open the file for
exclusive
access to determine if the copy operation is completed, but this still
doesn't seem to work all the time.
Any ideas would be greatly appreciated.
Thanks,

Nov 28 '06 #3
Hi
i had the same problem

So i create a file queue (a simple ilist) and a timer
on a file created event i try to process the file (for example for moving it
into another directory)
if the process fail i add the file reference in queue

every 60secs (for example) for each file in the queue i create a thread who
process the file
if the process is complete i delete file from queue
else this file will be reprocessed at the next tick

Thierry
"somequestion" <so**********@gmail.coma ecrit dans le message de news:
OI**************@TK2MSFTNGP06.phx.gbl...
Hi,

I'm trying to use FileSystemWatcher to determine when a new file has been
added to a directory. However, after the file has been added, I need to
process the file. This results in a problem if the file is large and takes
time to copy, as the events appear to get received before the copy is
finished.
I've tried listening to the Created event, as well as the Changed event
(which gets fired multiple times) based on the last write time. When
listening to the event, I try checking if I can open the file for
exclusive
access to determine if the copy operation is completed, but this still
doesn't seem to work all the time.
Any ideas would be greatly appreciated.
Thanks,

Nov 28 '06 #4
I fixed the same thing in my program by getting file info, waiting a
specififed amount of time (I used 3-tenths of a second) then checking
fileinfo.length again.

PSeudoCode :

Do
{
Size1 = FileInfo(myFile).length;
Thread.Sleep(300);
Size2 = FileInfo(myFile).length;
} while (Size1 != Size2);
This simply waits until the file stops growing before processing. It is
notably a hack, but it works like a dream in my system.

somequestion wrote:
Hi,

I'm trying to use FileSystemWatcher to determine when a new file has been
added to a directory. However, after the file has been added, I need to
process the file. This results in a problem if the file is large and takes
time to copy, as the events appear to get received before the copy is
finished.
I've tried listening to the Created event, as well as the Changed event
(which gets fired multiple times) based on the last write time. When
listening to the event, I try checking if I can open the file for exclusive
access to determine if the copy operation is completed, but this still
doesn't seem to work all the time.
Any ideas would be greatly appreciated.
Thanks,
Nov 28 '06 #5

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

Similar topics

1
by: Troy Murphy | last post by:
How do I prevent the FileSystemWatcher event to keep firing while the file is being created? When copying a file to the watched folder, the event fires a dozen or more times! Also, the...
7
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...
2
by: Jet Leung | last post by:
Hi all, I had made a program to watching files in my directory. I had used a instance of FileSystemWatcher to do my work.And I had add some events of the FileSystemWatcher , for example onChange,...
13
by: David | last post by:
I have been working on trying to write a directory watcher service. One of the requirments is that it be able to watch multiple directories, not sub directories of one parent directory, but just...
3
by: Stampede | last post by:
Hi, I want to use the FileSystemWatcher in a Windows Service. I read an article, where the author created the FileSystemWatcher object in a seperate thread and when the event is fired, he started...
20
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business...
12
by: ljh | last post by:
Has anyone else noticed that the FileSystemWatcher raises the changed event twice when a file is changed? Do you have any idea why this is the case?
5
by: Goran Djuranovic | last post by:
Hi all, I have a file system watcher service that works fine on a local hard drive, but will not work across the network. I tried both: mapping the drive and "\\..." path both no luck. I don't...
5
by: =?Utf-8?B?Sm9obiBT?= | last post by:
I am trying to find out if there is a way to tell if there is already a filesystemwatcher (created by a webservice) monitoring a folder. I have a webservice that creates a filesystemwatcher,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.