Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows FileSystemWatcher question 1

Status
Not open for further replies.

sallyan

Programmer
Sep 26, 2004
3
0
0
US
***program:*****************************
try to use a c# FileSystemWatcher to trigger process on events such as filecreation, filerenamed, etc
***problem:******************************
the program works fine with manual (mouse) creation of file, but I wrote a file generator to automaticly generate files, code as :
File.Create("c:/myfile1.txt");
File.Create("c:/Myfile2.txt);
...
the FileSystemWatcher wouldn't detect this kind of file creation. sometimes it says "process is being in use" sth like that.
***question***************************:
does anyone have any idea about how the windows file system works?
Thanks!


 
Whilst I am not familar wiht c#....

I am having a similar issue with ReadDirectoryChangesW. AFAIK, the function can return whilst the writing process still has the the file locked i.e. before the file is completely written.

I have not yet had time to alter my code to wait until I can get an exclusive lock on the file.

I am looking at using the LockFile (or LockFileEx) api to ensure that I have exclusive access.


Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
thanks Matt, hope you work that out soon.
 
getting a lock on the file worked for me...

Sorry I was a bit unclear. I am using LockFile as a test, if the call succeeds, then I have a lock, so the file write must be complete and vice versa. If you do go this way, and get a successful lock - don't forget to unlock it afterwards!

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
if I have a lock so the owner cannot write to it, then I cannot do it, but if I have a read lock and the owner still can write it, It would be what I need. can I do that?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top