Results 1 to 3 of 3

Thread: [RESOLVED] [2.0] Possible? Determine if a windows-related event triggered -- then do something

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    56

    Resolved [RESOLVED] [2.0] Possible? Determine if a windows-related event triggered -- then do something

    Here's the situation:

    I have a log file that I want to monitor. This log file will get updated based on certain events that happen within the program that writes the file (this program isn't written by me).

    What I want to do is, if that log file gets updated (a new line is added), I want my program to know this happened.

    I'm fairly certain I could rig a timer to check it every xx seconds. Check the filesize on the log, if it differs than the last time I opened it, then it's been modified. I don't want to do this because I assume it'll be pretty CPU intensive if I have to keep opening a file to check the last line every 1-2 seconds. This log file has the potential to become pretty big (upwards of 500-600kb, maybe even push 1mb).

    Is there a way I can write something that magically knows if the file has changed without it being on a timer?
    Last edited by ThisIsMyUserName; Nov 8th, 2006 at 05:10 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Possible? Determine if a windows-related event triggered -- then do something

    Use a FileSystemWatcher component. It's in the VS Toolbox.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    56

    Re: [2.0] Possible? Determine if a windows-related event triggered -- then do something

    Wow nice, worked perfect. I almost can't believe this component exists.

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