Access to file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Q2hyaXN0aWFuIEhhdmVs?=

    #1

    Access to file

    Hi,

    I have the following situation:

    -app1 writes data to a file
    -app2 (a service) is notified when the file is changed using the
    FileSystemWatch er
    -app2 reads the last added data and should remove the read data from the
    file

    Well, I think I can get a problem, if app1 tries to write data to the file,
    while app2 is removing the content from the file at the same time. How can
    this problem be solved?
    Christian
  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: Access to file

    Hi,

    Can you use some other mechanism than a file?
    Otherwise, can you create separated files each time App1 has something to
    write (App2 can delete the consumed files afterwards)

    --
    Ignacio Machin
    The #1 Warehouse Management System & Direct Store Delivery Software (DSD) for QuickBooks & ERP Systems – LaceUp Solutions

    Mobile & warehouse Solutions.
    "Christian Havel" <ChristianHavel @discussions.mi crosoft.comwrot e in
    message news:58BFDCCC-2484-47C6-929B-9E88DA0B928B@mi crosoft.com...
    Hi,
    >
    I have the following situation:
    >
    -app1 writes data to a file
    -app2 (a service) is notified when the file is changed using the
    FileSystemWatch er
    -app2 reads the last added data and should remove the read data from the
    file
    >
    Well, I think I can get a problem, if app1 tries to write data to the
    file,
    while app2 is removing the content from the file at the same time. How can
    this problem be solved?
    Christian

    Comment

    • Olie

      #3
      Re: Access to file

      For this very reason, when you try and write to a file the operating
      system will lock the file preventing other applications from using it.
      I think you can use the FileSystemMonit or to tell you when this lock
      is removed. Then you know when it is safe to try and write to it.

      The other way to do it is to ensure that only app1 actually writes to
      the file. You could do this by having another file written to by app2
      telling app1 what data needs to be deleted.

      Comment

      • =?Utf-8?B?Q2hyaXN0aWFuIEhhdmVs?=

        #4
        Re: Access to file

        Thanks for your help.
        Is the file locked if I only read from it, too?
        Christian

        "Olie" wrote:
        For this very reason, when you try and write to a file the operating
        system will lock the file preventing other applications from using it.
        I think you can use the FileSystemMonit or to tell you when this lock
        is removed. Then you know when it is safe to try and write to it.
        >
        The other way to do it is to ensure that only app1 actually writes to
        the file. You could do this by having another file written to by app2
        telling app1 what data needs to be deleted.
        >
        >

        Comment

        • Olie

          #5
          Re: Access to file

          The file lock allows multiple readers but only one writer.

          When the file is locked for writing only that application may write or
          read from the file.

          When a file is locked for reading any application can read from that
          file and no application can write to it.



          Comment

          • =?Utf-8?B?Q2hyaXN0aWFuIEhhdmVs?=

            #6
            Re: Access to file

            Thanks Olie :-)

            "Olie" wrote:
            The file lock allows multiple readers but only one writer.
            >
            When the file is locked for writing only that application may write or
            read from the file.
            >
            When a file is locked for reading any application can read from that
            file and no application can write to it.
            >
            >
            >
            >

            Comment

            Working...