Results 1 to 5 of 5

Thread: Watching a text file being written to, then when finished loading it into a text fil

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    Watching a text file being written to, then when finished loading it into a text fil

    Hi Everyone,

    Is there a way VB.NET 2005 can watch a text file be written to, then once the writing stops VB can know to pull the text file into a listbox? Any help would be much appreciated.

  2. #2
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: Watching a text file being written to, then when finished loading it into a text fil

    What program is used to edit the text file?
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    Re: Watching a text file being written to, then when finished loading it into a text

    I am calling a command line programmatically inside of my vb.net program (see below)

    Code:
    Shell(Environ$("comspec") & " /k net view > " & Chr(34) & "C:\netview.txt" & Chr(34), AppWinStyle.Hide)

    Then I am having my app sleep while the file builds (see below)

    Code:
    Dim x As Long = 1200 'in milliseconds
    System.Threading.Thread.Sleep(x) 'wait for 1200 milliseconds

    Then the app pulls the text file into a listbox after the sleep is complete.


    The problem is that sometimes I don’t specify a long enough time to sleep and VB doesn’t pull all the data because the file was still being written to.

    I am trying to find a way for VB to check and see when the file is done being written to, so I will have a more ironclad way of pulling all the data from the text file and not just a partial piece of it.

  4. #4
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: Watching a text file being written to, then when finished loading it into a text fil

    Use a timer to check the file at intervals rather than trying to force your thread to sleep for a certain period of time.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    Re: Watching a text file being written to, then when finished loading it into a text

    How can I check to see if the file is done?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width