March 28, 2012 at 6:03 pm
I have a FileSystemWatcher app that is watching a folder for any file creations events and when theya are raised I am attempting to open the file and complete a hash of its contents to be saved out to a database. The problems start when the file is locked by some other processes. I receive an access file error and the app fails to complete the hash. Does any one know of some way to ping the file and be alerted to when it is available to be opened so a hash can be completed?
Thanks,
Sean
A clever person solves a problem. A wise person avoids it. ~ Einstein
select cast (0x5365616E204465596F756E67 as varchar(128))
March 28, 2012 at 8:49 pm
The only way I know is to try accessing the file in a try/catch and if you catch a file access exception sleep for 5 seconds before trying again. Using exceptions for control flow is an anti-pattern, but AFAIK it's the only way in this scenario.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
March 28, 2012 at 9:24 pm
opc.three: Once again you surpass the brilliant. That is a great suggestion. I love the way you think!
A clever person solves a problem. A wise person avoids it. ~ Einstein
select cast (0x5365616E204465596F756E67 as varchar(128))
March 29, 2012 at 6:47 pm
Just to be closure to my post. I decided to copy the file to a staging folder and do the hash on that file. Seems to work really well.
TeraByteMe (3/28/2012)
opc.three: Once again you surpass the brilliant. That is a great suggestion. I love the way you think!
A clever person solves a problem. A wise person avoids it. ~ Einstein
select cast (0x5365616E204465596F756E67 as varchar(128))
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply