Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Filesystemwatcher synchronous
Message
From
01/09/2009 15:48:09
 
 
To
01/09/2009 07:44:42
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Vista
Miscellaneous
Thread ID:
01422062
Message ID:
01422211
Views:
42
I just Googled [filesystemwatcher "file closed"]. The top hit discusses using a PDF printer driver: http://stackoverflow.com/questions/561467/filesystemwatcher-waitforchanged-returns-but-there-is-still-a-lock-on-the-file

Based on that, you may end up having to poll for an exclusive lock.

>Thanks Al. It is definitely a matter of timing. The PDFCreator is spooling the write off to create the PDF and then execution is continuing. Unfortunately, the next line needs to have the PDF file fully written before it will work.
>
>My understanding of the filesystemwatcher is that it can be used to synchronously wait for a file to be written. But in the examples I can't figure out how to sequence the writing and the instruction to wait.
>
>I always considered the timer stuff a kludge and one of the things I like so much about .net is the ability to talk to the OS more directly. I'm going to study the two links you sent to see if I can find some clues there, but I am hoping someone who has been down this road will chime in with a magic solution using filesystemwatcher correctly.
>
>>A little while ago I was looking at doing something similar in VFP. There is a VFP Solutions example based on the Win32 API ShChangeNotifyRegister function. I was warned there are some potential issues with this e.g.
>>
>>1. Combined notifications: http://msdn.microsoft.com/en-us/library/bb762120%28VS.85%29.aspx
>>
>>2. Possible deprecation on current/future OSs (i.e. Vista and later): http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/75fab037-f31e-4cbc-8b64-bb0e6f339f75
>>
>>Why is this relevant to you? *If* the .Net functions are wrappers around these API functions they may exhibit some of the same foibles. Even if they aren't, it might be worth asking around regarding any gotchas.
>>
>>I ended up using ADIR() fired by a timer. In my case, a video can start being written (real-time capture) to a folder, but not be finished for a minute or two. I check for the capture being finished by periodically attempting to obtain a file lock via FOPEN().
>>
>>In your case, what you may need to look for is some sort of "lock released" event on a file that you know has just been created (if such an event exists). If an event like that doesn't exist, you might have to try a looped/timered low level file open, like I did in VFP. My understanding is, at the basic file system level, the only way you can be sure that another process isn't using a file (or is finished using it) is if you can obtain exclusive access.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform