Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Filesystemwatcher synchronous
Message
De
01/09/2009 09:22:36
 
 
À
01/09/2009 07:44:42
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Vista
Divers
Thread ID:
01422062
Message ID:
01422135
Vues:
34
>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.

The only solutions I've seen to this revolve around attempting to get a handle on the file when the Changed event fires - which is obviously a bit of a kludge.

Here's a generic example: http://geekswithblogs.net/thibbard/articles/ExtendingFileSystemWatcher.aspx
One thing I might change though is to increase the delay between attempts after each failure...

FWIW it looks as if FilSystemWatcher is just a wrapper for the ReadDirectoryChangesW() Win API method....
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform