Mutux - blocking multiple apps accesing the same file

  • Thread starter Thread starter Phil Jones
  • Start date Start date
P

Phil Jones

Is there a way to use a Mutex (or something) to block access to a file
between different running applications.

The situation is this - I have more than one application running, and they
all share the same XML file. What I want to do is block other apps from
writing to the file when one app is in the process of update/saving it.

Thanks for any advice!
===
Phil : New Zealand
 
Use a named mutex is one way. All the apps need to respect the mutex
however, but sounds like that is workable for you. Before writing, an app
grabs the mutex and releases it when done. Other apps can block until they
get the mutex. You may instead use something like FileShare.None, but that
may not work too well as you would have to poll on the file I think.
 
That sound good William.

I'm new to working with the [Mutex] object.

One query here - when you say the "app grabs the mutex" - can that be done
by creating a Mutex with the same name (eg "MyMutex") or is there some
global repository of Mutex objects??

Thank you very much.

===
Phil
 
Skeet
its a good idea to push these articles to the community solutions section on
MSDN so that developers who don't read the newsgroups can have access to
this content. It will also allow you to hang on to your MVP status :-)

--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
--------------------------------------------------


Jon Skeet said:
Phil Jones said:
That sound good William.

I'm new to working with the [Mutex] object.

One query here - when you say the "app grabs the mutex" - can that be
done
by creating a Mutex with the same name (eg "MyMutex") or is there some
global repository of Mutex objects??

See http://www.pobox.com/~skeet/csharp/faq/#one.application.instance
 
its a good idea to push these articles to the community solutions section on
MSDN so that developers who don't read the newsgroups can have access to
this content.

Pretty much everyone's got access to groups.google.com - and they've
got access to my web site too. It's easier to maintain my own website
than MSDN articles...
 
Back
Top