Something I am working on at the moment requires multi user updating of files and I'm trying to work out the best way of doing it in C#.
The C# code is in a component being called from some "classic" ASP pages. The component reads files from the web server file system, makes changes to the data and then saves the files again.
The application is multi user (and even without mulitple users there is scope for simultaneous updates to files).
The C# component needs to get some sort of lock on a file when reading it in preparation of a write. If it can't get a lock it needs to wait until it can (and probably give up after a certain period has passed). It can't try to get a lock, fail and then return to the calling code for it to try again later.
All this probably needs to work across processes and definitely across threads.
Performance isn't critical.
I am starting to read up .NET multi-threading and locking. Most of it seems to assume that you are trying to control access to managed objects. In my case however I am controlling access to physical files.
I think the cross-process requirements mean that of the various .NET thread syncronisation schemes Mutex is the only one available to me. I am wondering if I can just use file locking to achieve it though?
The other issue is waiting. Whenever the docs talking about waiting on a lock of some sort they talk about the "thread" blocking until the lock is available. This sounds bad to me when the thread in question could be an ASP worker thread, which could be busy doing other stuff.
Does anyone have any experience in this area?
_________________________
Remind me to change my signature to something more interesting someday