private bool IsFileLocked(FileInfo file)
{
FileStream stream = null;
try
{
stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None);
}
catch (IOException)
{
//the file is unavailable because it is:
//still being written to
//or being processed by another thread
//or does not exist (has already been processed)
return true;
}
finally
{
if (stream != null)
stream.Close();
}
//file is not locked
return false;
}
Last edited by fcronin; July 21st, 2011 at 12:14 PM.
Please place code within (CODE)(/CODE) tags... but use [ ] rather than ( )...
You can explain this more easily if you use [noparse] and [/noparse] tags to surround [code] and [/code] tags. So when you're editing the final thing looks like (in the editor window):
"Please use [noparse][code] and [/code][/noparse] tags around code"
and renders as:
"Please use [code] and [/code] tags around code"
Best Regards,
BioPhysEngr http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Thanks for the replies.
I've got around it for now by having my program copy the file and then read that when it needs to.
Not ideal, but works for now.
Generally, the monitoring program must support it by not locking the file (it has to open it in shared mode). This OS/file system matter, so your options are limited. If it is possible, it would be better to use database as the store.
You can explain this more easily if you use [noparse] and [/noparse] tags to surround [code] and [/code] tags. So when you're editing the final thing looks like (in the editor window):
"Please use [noparse][code] and [/code][/noparse] tags around code"
You can explain this more easily if you use [noparse] and [/noparse] tags to surround [code] and [/code] tags. So when you're editing the final thing looks like (in the editor window):
"Please use [noparse][code] and [/code][/noparse] tags around code"
and renders as:
"Please use [code] and [/code] tags around code"
Nice!! I've been around for ten years, and I've never even seen those tags! Thanks!
I always use the HTML ascii code for the square brackets, for example:
& #91; ( without the space ) gives you [ and & #93; ( without the space ) gives you ]
Bookmarks