VS 2010 System Timer is better than FileSystemWatcher - do you agree?-VBForums
Results 1 to 22 of 22

Thread: System Timer is better than FileSystemWatcher - do you agree?

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,448

    System Timer is better than FileSystemWatcher - do you agree?

    I am writing an application (windows servcie) that processes files once they are created. I didn't know if I should use a timer or a filesystemwatcher. I googled the difference, and a small sampling of people said they found filesystemwatcher to be unreliable. Do you agree? I remember writing an application with the FSW about five years ago and I don't recall any issues. And I think it would have been improved in VS2010. So thanks for any opinions on this.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,962

    Re: System Timer is better than FileSystemWatcher - do you agree?

    Hello there,

    Personally, I have never had an issue with the FileSystemWatcher, so I would have suggested that you go with that. The other option would be to provide a public method on the Windows Service such that (assuming you are in control of the system that is writing the file into a folder) you could poke this method to then continue the processing of the file.

    Gary

  3. #3

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,448

    Re: System Timer is better than FileSystemWatcher - do you agree?

    Gary,

    I might need to do this poking. When I tested with the fsw, things went fine. Now I am ready to deploy to my first live website (the app is general purpose and will be run in many of our websites). I just tested again because I had to do some customization/coding changes for said website, and I created four folders in the directory that I am watching. It only recognized two of them. I cut/pasted the other two, and then they were recognized.

    These folders get created at "exactly the same time" (or as close to it as possible by a computer) because I am placing an online order. My order contained four items. A folder is created for each item. Are the folders created too close together? I really wish I wasn't finding this now when I have a deadline to deploy since I had said it was finished over a month ago...
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  4. #4

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,448

    Re: System Timer is better than FileSystemWatcher - do you agree?

    I tested again with four items and it was fine. The previous test I had breakpoints and stopped in my code a couple times, so I will blame it on myself and hope for the best. When it runs live and well for a couple days, I will resolve the post. Thanks!
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  5. #5
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,605

    Re: System Timer is better than FileSystemWatcher - do you agree?

    ASP.NET forum is probably not the best place to get Windows Service help either. Might want to have it moved to the VB.NET forum.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  6. #6

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,448

    Re: System Timer is better than FileSystemWatcher - do you agree?

    I got the help I wanted. It's pretty much resolved. But thanks for the suggestion (even though it's in C#).
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  7. #7

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,448

    Re: System Timer is better than FileSystemWatcher - do you agree?

    The FileSystemWatcher has failed me!

    My windows service has not been recognizing the creation of new files since 1/18/12! There is not a ton of activity of files getting created but still, this service is running in a live web deployment and people are expecting to get their files. So I feel like I picked the wrong foundation.

    It's monitoring a folder called xxx\output and in there subfolders get created. I just deleted a subfolder, restarted my process, copied the folder back in, and it was processed (this is sort of what I said in one of my posts above, but I blamed it on my own testing and controlling (debugging) the code). There is nothing wrong with the logic, just the foundation I build it on.

    I am sad...
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  8. #8

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,448

    Re: System Timer is better than FileSystemWatcher - do you agree?

    My boss just emailed our IT person to ask if there was a system patch applied after 1/18. Is it possible something like that could break it? I told him he was asking the wrong person for an explanation, but maybe it is I who is wrong.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  9. #9
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,962

    Re: System Timer is better than FileSystemWatcher - do you agree?

    Hmmm, I have found the FileSystemWatcher to be very good at what it does. I don't think I have ever seen anything being missed

    As to whether a system patch could have caused a problem, I am really not sure. Certainly a possibility, but I couldn't say for sure.

    Are you pointing the FileSystemWatcher at a network share, or is it a local folder?

    Gary

  10. #10
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,962

    Re: System Timer is better than FileSystemWatcher - do you agree?

    The FileSystemWatcher does have this:

    http://msdn.microsoft.com/en-us/libr...ingevents.aspx

    Which might give you an indication of whether it is currently "working". You could possibility look to test this on a periodic basis.

    Gary

  11. #11

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,448

    Re: System Timer is better than FileSystemWatcher - do you agree?

    Quote Originally Posted by gep13 View Post
    Hmmm, I have found the FileSystemWatcher to be very good at what it does. I don't think I have ever seen anything being missed

    As to whether a system patch could have caused a problem, I am really not sure. Certainly a possibility, but I couldn't say for sure.

    Are you pointing the FileSystemWatcher at a network share, or is it a local folder?

    Gary
    It is a network share.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  12. #12

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,448

    Re: System Timer is better than FileSystemWatcher - do you agree?

    Quote Originally Posted by gep13 View Post
    The FileSystemWatcher does have this:

    http://msdn.microsoft.com/en-us/libr...ingevents.aspx

    Which might give you an indication of whether it is currently "working". You could possibility look to test this on a periodic basis.

    Gary
    Okay, so that call (EnableRaisingEvents) gets or sets a value indicating whether the component is enabled. which means I could check it and if it's false set it to true again? I do have a timer that goes off every 24-hours, so this is a feasible check (which would answe my boss's question, how do we know if it happens again?)
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  13. #13

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,448

    Re: System Timer is better than FileSystemWatcher - do you agree?

    My coworker says she uses them all the time without incident. And she is probably running on the same server as me (though I am not sure about that).

    If my code were bad, why it work so well for days then just break? Maybe I should look at her code and find out her trick. But it's really such a simple process, I don't understand what could've gone wrong.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  14. #14
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,962

    Re: System Timer is better than FileSystemWatcher - do you agree?

    Quote Originally Posted by MMock View Post
    It is a network share.
    Ah. A quick google on that fact suggested that there is a known "issue" with using a FileSystemWatcher on a network share

    Yes, that would be the idea, set it to True again. However, doing this on a 24 hour basis would mean that potentially, you would miss some additions, and you would need to keep a record of processed files.

    Gary

  15. #15

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,448

    Re: System Timer is better than FileSystemWatcher - do you agree?

    So if I checked the enabled switch and it was false, I could renable it and alert myself somehow. Then I'd have to go make up no more than one day's worth (still possibly a lot) of file creation events.

    This is a stupid question, but what actually is a disconnection of the network share? It can happen if the server is rebooted? Which wouldn't happen to a local watcher because both the fsw and the folder it's watching would get knocked out of the water and they'd both come back up together?

    I should find out if that server was rebooted on the day the fsw got sick!
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  16. #16
    PowerPoster
    Join Date
    May 2002
    Posts
    25,961

    Re: System Timer is better than FileSystemWatcher - do you agree?

    Oh... yes... I bet I know what happened... if the folder being watched is on a network share, and the link is severed - power outage, network drop, watched server goes off line.... and the FSW isn't re-started.... it will fail... there's something in the grey matter that's tingling that I might have run in to this a loooooong time ago... and might be why I never use it to watch network shares... I try to have it watch local folders (which could be shared) instead.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  17. #17

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,448

    Re: System Timer is better than FileSystemWatcher - do you agree?

    Yes, I am starting to suspect that, too. I *have* to watch a network share. Our web site deployment runs on machine A and the fileserver is on machine B. I need to get stuff from the deployment so I have to be on that machine.

    So I guess I just have to be apprised of restarts - if that is even possible.

    Of course, my co-worker over the wall is saying she has never had this problem happen to her.

    I guess I can test it because I have two PC's. I can watch files on P-4 from P-14, reboot P-4 and see what happens. That will take a long time. Development is over on this project!
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  18. #18
    PowerPoster
    Join Date
    May 2002
    Posts
    25,961

    Re: System Timer is better than FileSystemWatcher - do you agree?

    You don't even need to reboot.... just unplug the netwrok cable from the machine that's being watched.... wait... then plug it back in and see if new files there get picked up...
    Might be faster than rebooting the system.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  19. #19

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,448

    Re: System Timer is better than FileSystemWatcher - do you agree?

    Thanks for the tip, tg (you seem to know that I usually have 15 windows open and yes, rebooting is a big deal to me!). I will only do that test if I feel it is necessary, based on what my coworker said about how the FSW never fails her over the network. She is not in yet, but I looked at her project code and I do not even see that she is using a FSW. She is using a timer. So maybe she is confusing me saying "filesystemwatcher" with her use of a process that examines the file system on timer elapsed events. Thanks.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  20. #20
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,962

    Re: System Timer is better than FileSystemWatcher - do you agree?

    Hey,

    Just catching up on threads, been away for the weekend...

    What was the outcome of this? Were you able to do the test that you mentioned?

    Gary

  21. #21

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room, trying to forget the past
    Posts
    3,448

    Re: System Timer is better than FileSystemWatcher - do you agree?

    I don't know when I will have time to test that. As you may have realized (from my MVC thread you've posted to) I am up to "here" trying to learn MVC for a new, hot project. And what I may end up doing with the fsw is run it on the file server machine instead of the web server. I said in post #17 that I have to watch a fileshare but that may not be true. I have to get deployment values from websites, but I don't have to be on the website machine to do that - I don't know why I just realized that. So I will probably end up moving things around a bit. (Don't worry about missing out on anything - I am usually also away for the weekend, even if only mentally!)
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  22. #22
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,962

    Re: System Timer is better than FileSystemWatcher - do you agree?

    Ah, that might just solve your problem then.

    As I said, I haven't had a problem with the FSW when running locally. Good luck with MVC.

    Gary

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.