R
Roger Helliwell
My web app writes all error/diagnostic messages to an error file in
Xml format. It seemed to be working fine, until I wrote a Windows app
that listens for changes in this file. If the file changes, the file
is loaded and displayed in a form for the administrator to review.
Now it seems there are (occasionally) times when the web-app fails
while trying to write to the file. Presumably this is due to the fact
that the Windows app is currently loading the file. I'm using
XmlDocument.Load() for this.
For now, I've wrapped my 'append an error' code in a loop which
repeatedly tries again if a FileAccess exception is caught. But there
must be a safer way to accomplish this.
Is there any mechanism in .NET that allows an exclusive lock on file?
Preferably one that causes any write request to wait until the lock is
released?
Thanks,
Roger
Xml format. It seemed to be working fine, until I wrote a Windows app
that listens for changes in this file. If the file changes, the file
is loaded and displayed in a form for the administrator to review.
Now it seems there are (occasionally) times when the web-app fails
while trying to write to the file. Presumably this is due to the fact
that the Windows app is currently loading the file. I'm using
XmlDocument.Load() for this.
For now, I've wrapped my 'append an error' code in a loop which
repeatedly tries again if a FileAccess exception is caught. But there
must be a safer way to accomplish this.
Is there any mechanism in .NET that allows an exclusive lock on file?
Preferably one that causes any write request to wait until the lock is
released?
Thanks,
Roger