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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to get info from a file when it is being used by another process?

How to get info from a file when it is being used by another process?

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestionannouncement
4 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.
  • V Offline
    V Offline
    Vivek Narayanan
    wrote on last edited by
    #1

    I need this to update a progress bar.First a DOS service is run in the background , which writes a log file as it runs , the percentage info can be retrieved (there is no other way to get the percentage since this is a dos service) from the log file,but i get an error that the file is being used by another process(the DOS one).Its pointless to get info from the log file after the DOS process completes,as i need it to update a progress bar.Is there any solution to this? Thanks in Advance, Regards, Vivek

    L D 2 Replies Last reply
    0
    • V Vivek Narayanan

      I need this to update a progress bar.First a DOS service is run in the background , which writes a log file as it runs , the percentage info can be retrieved (there is no other way to get the percentage since this is a dos service) from the log file,but i get an error that the file is being used by another process(the DOS one).Its pointless to get info from the log file after the DOS process completes,as i need it to update a progress bar.Is there any solution to this? Thanks in Advance, Regards, Vivek

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, two attempts: 1. I think the following code works even when the file is still open (and being written to) by another process: FileInfo fi=new FileInfo(filename); log("size="+fi.Length); 2. there is a solution if the other process has created the file with a share mode of read or readwrite, meaning it allows other processes to simultaneously read or readwrite the same file. If it did, you now can open the same file with FileMode.Read and FileShare.ReadWrite (i.e. "I want to read" and "I allow others to read and write"). And one remark: files get buffered, the buffer gets written to disk for sure only when one closes the file, or performs a flush operation (forcing the physical write). So for small files that dont flush, watching the size might not be a good progress indication. :)

      Luc Pattyn


      try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


      V 1 Reply Last reply
      0
      • V Vivek Narayanan

        I need this to update a progress bar.First a DOS service is run in the background , which writes a log file as it runs , the percentage info can be retrieved (there is no other way to get the percentage since this is a dos service) from the log file,but i get an error that the file is being used by another process(the DOS one).Its pointless to get info from the log file after the DOS process completes,as i need it to update a progress bar.Is there any solution to this? Thanks in Advance, Regards, Vivek

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        If the other process opens and writes to it's file, denying shared read, there's nothing you can do. If it allows shared read by other applications while it's writing, then you can open the file using:

        Dim fs As New FileStream(_filepath_, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
        

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        1 Reply Last reply
        0
        • L Luc Pattyn

          Hi, two attempts: 1. I think the following code works even when the file is still open (and being written to) by another process: FileInfo fi=new FileInfo(filename); log("size="+fi.Length); 2. there is a solution if the other process has created the file with a share mode of read or readwrite, meaning it allows other processes to simultaneously read or readwrite the same file. If it did, you now can open the same file with FileMode.Read and FileShare.ReadWrite (i.e. "I want to read" and "I allow others to read and write"). And one remark: files get buffered, the buffer gets written to disk for sure only when one closes the file, or performs a flush operation (forcing the physical write). So for small files that dont flush, watching the size might not be a good progress indication. :)

          Luc Pattyn


          try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


          V Offline
          V Offline
          Vivek Narayanan
          wrote on last edited by
          #4

          Thanks a lot for giving the idea of using the file's length. Vivek

          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