Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Detecting Locked Files
Message
From
18/10/2005 10:37:14
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 1.1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01059899
Message ID:
01059906
Views:
13
This message has been marked as the solution to the initial question of the thread.
I assume that if the file is used somewhere else, the code to open it would produce an error. A simple solution might then be to use a try - catch block.

>Hi all,
>
>What is the proper way to determine if a file is locked by another process?
>
>I have a Windows service that handles File Create events from a File System Watcher. When a new file is created, it kicks off a new thread and goes back to sleep. The thread has a timer so it can sleep until the file has been completely written to disk. I am currently using the file size to determine when the file is no longer growing. That worked for another project where files were being created from an ftp download, but it doesn't work in this particular case. The files I'm dealing with now are being uploaded to a server as they are being recorded (streaming video). I think the file size is being reported as 0 until the file write is done (about 2 hours). Is there a way I can just ask the file if it's locked by another process? Then, I can just keep sleeping until the file is unlocked.
>
>TIA,
>Chad
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform