Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Blocking Multiple Application accessing the same file

Blocking Multiple Application accessing the same file

Scheduled Pinned Locked Moved C#
xml
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    girijaa
    wrote on last edited by
    #1

    Hi , I have two Applications , 1 being a Windows Service and the other one is a Windows Application . Both the Applications access an xml file which has to be modified under different scenarios . I want to avoid concurrent updates /Reads on the xml file from both the application . Tried using the ReadWriteLock for avoiding concurrent access on the file ,but it doesn't seem to work . Kindly suggest how this can be achieved . Thanks in Advance Girija

    C T 2 Replies Last reply
    0
    • G girijaa

      Hi , I have two Applications , 1 being a Windows Service and the other one is a Windows Application . Both the Applications access an xml file which has to be modified under different scenarios . I want to avoid concurrent updates /Reads on the xml file from both the application . Tried using the ReadWriteLock for avoiding concurrent access on the file ,but it doesn't seem to work . Kindly suggest how this can be achieved . Thanks in Advance Girija

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      CORRECTION: Open the file as FileShare.None[^] (one of the sharing options) - that way nothing else will be able to open the file. e.g.

      FileStream stream = new FileStream("C:\MyFile.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.None);


      Upcoming events: * Glasgow: Introduction to AJAX (2nd May), SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

      1 Reply Last reply
      0
      • G girijaa

        Hi , I have two Applications , 1 being a Windows Service and the other one is a Windows Application . Both the Applications access an xml file which has to be modified under different scenarios . I want to avoid concurrent updates /Reads on the xml file from both the application . Tried using the ReadWriteLock for avoiding concurrent access on the file ,but it doesn't seem to work . Kindly suggest how this can be achieved . Thanks in Advance Girija

        T Offline
        T Offline
        Tim Paaschen
        wrote on last edited by
        #3

        AFAIK the ReaderWriterLock is local to a process. You will have to use a named Mutex, that has system scope and thus can be shared between processes.

        Regards, Tim

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups