Re: lock an xmlfile
From: William LaMartin (lamartin_at_tampabay.rr.com)
Date: 02/02/04
- Next message: A.M: "Re: This page can not be saved"
- Previous message: Showjumper: "How to use verifyrenderinginserverform with a custom control?"
- In reply to: Peter Rilling: "Re: lock an xmlfile"
- Next in thread: Shawn: "Re: lock an xmlfile"
- Reply: Shawn: "Re: lock an xmlfile"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 1 Feb 2004 19:07:14 -0500
The problem I ran into when using Mutex is that in a shared hosting
environment, its use would throw a security exception. I could never really
get the hosting company to understand the problem. I am not even sure
anyone there understood the question--what needed to be set so as to allow
the use of Mutex. Mutex was not in their vocabulary.
Its use worked fine on my local setup, though. So if you have control over
the server, then I think Mutex is the way to go in restricting the use of
files while they are being updated.
"Peter Rilling" <peter@nospam.rilling.net> wrote in message
news:em7dkPI6DHA.1664@TK2MSFTNGP11.phx.gbl...
> Now you get into more interesting architectural issues.
>
> The simplest way might be a bruit force method in which you use the loop
but
> use a try...catch block so the exception does not bubble (I do not know
how
> to ask the OS if a file is locked).
>
> Another way might be to look into using the Mutex class. You could wrap
> access to the file so that a Mutex is always created when the file is
> opened, then released when closed.
>
> "Shawn" <bossman100@hotmail.com> wrote in message
> news:401b9580$1@news.wineasy.se...
> > Thanks Peter, I think that will do the trick. One thing though. If the
> > file is closed by another FileStream, is there a way I can wait until
the
> > file is no longer locked instead of just writing an error message to the
> > user? Something like this:
> > Do While file.isClosed
> > 'Just waiting for the file to open
> > Loop
> >
> > Thanks,
> > Shawn
> >
> >
> > "Peter Rilling" <peter@nospam.rilling.net> wrote in message
> > news:OFQxbk15DHA.2252@TK2MSFTNGP10.phx.gbl...
> > What happens is that the XML content is loaded entirely in memory and
the
> > DOM is created. So normally there are no connections to the file,
unlike
> > when you have a stream.
> >
> > Have not tried this but what you might try doing is to manually open the
> > file using the FileStream class (you can specify locks using the
FileShare
> > enumeration), then use that stream when you call the XmlDocument.Load.
> >
> >
> >
> > "Shawn" <bossman100@hotmail.com> wrote in message
> > news:401a8d8f$1@news.wineasy.se...
> > > Hi.
> > > I have a webservice method that receives an XmlNode. It then loads an
> > > existing xml file into an XmlDocument, appends the new XmlNode to the
> > > XmlDocument and saves it back to the xml file. But what if another
user
> is
> > > doing the same thing at the same time? I did a test and found out that
> the
> > > file is not automatically locked. Which means that the second user
> > > overwrites the changes the first user made. Any ideas on how I can
> prevent
> > > this?
> > >
> > > Thanks,
> > > Shawn
> > >
> > >
> > >
> >
> >
> >
>
>
- Next message: A.M: "Re: This page can not be saved"
- Previous message: Showjumper: "How to use verifyrenderinginserverform with a custom control?"
- In reply to: Peter Rilling: "Re: lock an xmlfile"
- Next in thread: Shawn: "Re: lock an xmlfile"
- Reply: Shawn: "Re: lock an xmlfile"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|