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. How to read a file that is always written to?

How to read a file that is always written to?

Scheduled Pinned Locked Moved C#
questiontutorial
11 Posts 6 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.
  • P Offline
    P Offline
    pistolenpaultje
    wrote on last edited by
    #1

    Hello everyone! My first post here :) As you might have guessed from the message title: is it possible to read from a text file, while another application is always writing to it, without disturbing the writing process? And if it is, how do I do it? I'd like to create an application that open such a file, and gets the data that has been added to the file since my last read (maybe you've got some good suggestions how to do that?). Thanks in advance, Paul

    G O C 3 Replies Last reply
    0
    • P pistolenpaultje

      Hello everyone! My first post here :) As you might have guessed from the message title: is it possible to read from a text file, while another application is always writing to it, without disturbing the writing process? And if it is, how do I do it? I'd like to create an application that open such a file, and gets the data that has been added to the file since my last read (maybe you've got some good suggestions how to do that?). Thanks in advance, Paul

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      It might be possible to read from the file, but it's hard to guarantee that it would never disturb the writing process. It sounds like you should use something that has much better functionality to handle multiple users, like a database. --- b { font-weight: normal; }

      P 1 Reply Last reply
      0
      • P pistolenpaultje

        Hello everyone! My first post here :) As you might have guessed from the message title: is it possible to read from a text file, while another application is always writing to it, without disturbing the writing process? And if it is, how do I do it? I'd like to create an application that open such a file, and gets the data that has been added to the file since my last read (maybe you've got some good suggestions how to do that?). Thanks in advance, Paul

        O Offline
        O Offline
        Office Lineman
        wrote on last edited by
        #3

        Are you talking about something similar to the Unix tail command? If so, you might just want to look at something like this[^]. -- I've killed again, haven't I?

        P 1 Reply Last reply
        0
        • G Guffa

          It might be possible to read from the file, but it's hard to guarantee that it would never disturb the writing process. It sounds like you should use something that has much better functionality to handle multiple users, like a database. --- b { font-weight: normal; }

          P Offline
          P Offline
          pistolenpaultje
          wrote on last edited by
          #4

          That is true, but my question was more out of curiosity after observing programs like AviPreview or VLAN play avi or mpg files while they were still being downloaded. I hope someone knows a solution because this is driving me nuts :wtf:

          E 1 Reply Last reply
          0
          • O Office Lineman

            Are you talking about something similar to the Unix tail command? If so, you might just want to look at something like this[^]. -- I've killed again, haven't I?

            P Offline
            P Offline
            pistolenpaultje
            wrote on last edited by
            #5

            i looked at that, but it waits until the writing process is complete and then opens the file and reads the changes. i'd like to know how to read a file that is being written to while it happens. Or, probably the same, an application that is writing to the file sporadically but never closes the file handle while it is running. thank you for your reply though, i'll get there! maybe this is good material for an article: Advanced File I/O :rolleyes:

            L 1 Reply Last reply
            0
            • P pistolenpaultje

              i looked at that, but it waits until the writing process is complete and then opens the file and reads the changes. i'd like to know how to read a file that is being written to while it happens. Or, probably the same, an application that is writing to the file sporadically but never closes the file handle while it is running. thank you for your reply though, i'll get there! maybe this is good material for an article: Advanced File I/O :rolleyes:

              L Offline
              L Offline
              likefood
              wrote on last edited by
              #6

              I'm not sure how helpful this is, but I accidentally did something like that a while back. I wrote a program that was supposed to start capturing the screen into a WMV. I made the mistake of telling it to start capturing when it lost focus, as well as play the captured file when I manually stopped it. The result was this: - captured WMV (wrote file) - played WMV in MediaPlayer - program lost focus - program started writing to same WMV just before MP started playing it - I saw the multiple smaller-and-smaller time-delayed MediaPlayer windows in the video. Basically, MediaPlayer was reading a file that was being written just a little ahead of it, so I know it's POSSIBLE. It's just a matter of fooling Windows into doing it intentionally. -Daniel

              P 1 Reply Last reply
              0
              • L likefood

                I'm not sure how helpful this is, but I accidentally did something like that a while back. I wrote a program that was supposed to start capturing the screen into a WMV. I made the mistake of telling it to start capturing when it lost focus, as well as play the captured file when I manually stopped it. The result was this: - captured WMV (wrote file) - played WMV in MediaPlayer - program lost focus - program started writing to same WMV just before MP started playing it - I saw the multiple smaller-and-smaller time-delayed MediaPlayer windows in the video. Basically, MediaPlayer was reading a file that was being written just a little ahead of it, so I know it's POSSIBLE. It's just a matter of fooling Windows into doing it intentionally. -Daniel

                P Offline
                P Offline
                pistolenpaultje
                wrote on last edited by
                #7

                That's exactly what i mean! Funny though, because I never caught WMP doing anything like that (it refuses to play avi's or mpg's while the download is still in progress). Maybe it's because WMV's are designed with streaming in mind, so WMP opens it differently than avi's or mpg's.. Paul

                L 1 Reply Last reply
                0
                • P pistolenpaultje

                  That's exactly what i mean! Funny though, because I never caught WMP doing anything like that (it refuses to play avi's or mpg's while the download is still in progress). Maybe it's because WMV's are designed with streaming in mind, so WMP opens it differently than avi's or mpg's.. Paul

                  L Offline
                  L Offline
                  likefood
                  wrote on last edited by
                  #8

                  I'm not very knowledgeable about streaming or deep file IO junk, but it would make sense for WMP to check to see if the file is not currently being written to. In my scenario, I wouldn't be surprised if my program hadn't quite started writing to the file when WMP checked it (the WMV was a distinct file from a previous start-stop capture), kind of like how people used to play copied PS games (I never did, but I heard how to do it, with a real disk when the PS does its little preliminary validity check, then swapping). -Daniel

                  1 Reply Last reply
                  0
                  • P pistolenpaultje

                    That is true, but my question was more out of curiosity after observing programs like AviPreview or VLAN play avi or mpg files while they were still being downloaded. I hope someone knows a solution because this is driving me nuts :wtf:

                    E Offline
                    E Offline
                    Ed Poore
                    wrote on last edited by
                    #9

                    pistolenpaultje wrote:

                    AviPreview or VLAN play avi or mpg files while they were still being downloaded

                    I don't know about these programs but it looks like LimeWire just pauses the download while it writes the downloaded bits so far to a temporary file which it then displays. Maybe these programs do the same and you havn't realised.


                    You know you're a Land Rover owner when the best route from point A to point B is through the mud. Ed

                    1 Reply Last reply
                    0
                    • P pistolenpaultje

                      Hello everyone! My first post here :) As you might have guessed from the message title: is it possible to read from a text file, while another application is always writing to it, without disturbing the writing process? And if it is, how do I do it? I'd like to create an application that open such a file, and gets the data that has been added to the file since my last read (maybe you've got some good suggestions how to do that?). Thanks in advance, Paul

                      C Offline
                      C Offline
                      CiNN
                      wrote on last edited by
                      #10

                      you just have to keep tracks of the position of the writing process and limit yourself to not read beyond where the last write position was.

                      P 1 Reply Last reply
                      0
                      • C CiNN

                        you just have to keep tracks of the position of the writing process and limit yourself to not read beyond where the last write position was.

                        P Offline
                        P Offline
                        pistolenpaultje
                        wrote on last edited by
                        #11

                        sounds like just what i need! however i already tried something like that but couldn't get it to work. do you have any suggestion (maybe an article link or code snippet) how i could accomplish that? many thanks for your reply, i now have an idea in what direction to search!:cool:

                        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