Service executes twice

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom Van den Brandt

    #1

    Service executes twice

    Hi,

    I wrote a simple windows service that includes a FileSystemWatch er.
    After building and installing the service (installutil) I notice that
    the service executes twice. I included a write to the application
    eventlog in OnStart ("service has started and is ready to watch the
    filesystem") and this results in two entries in the eventlog.

    Also, the handler for the FileSystemWatch er seems to be fired twice if
    something happens with a file the service is watching.

    I checked the machines services and in the task manager but I see only
    one instance of the service running.

    I'm a newbie at this, so I probably missed something obvious... Could
    this be the properties of the service that were not correctly configured?

    Any ideas?

    Thx,

    Tom
  • Harry

    #2
    Re: Service executes twice

    "Tom Van den Brandt" <guineapig@guin eapig.bewrote in message
    news:uJud95IIIH A.4684@TK2MSFTN GP06.phx.gbl...
    Hi,
    >
    I wrote a simple windows service that includes a FileSystemWatch er.
    After building and installing the service (installutil) I notice that
    the service executes twice. I included a write to the application
    eventlog in OnStart ("service has started and is ready to watch the
    filesystem") and this results in two entries in the eventlog.
    >
    Also, the handler for the FileSystemWatch er seems to be fired twice if
    something happens with a file the service is watching.
    >
    I checked the machines services and in the task manager but I see only
    one instance of the service running.
    >
    I'm a newbie at this, so I probably missed something obvious... Could
    this be the properties of the service that were not correctly configured?
    >
    Any ideas?
    >
    Thx,
    >
    Tom
    Tom, often we look at code and miss that what we are trying to accomplish is
    often sabotaged by lack of observation or object/control events. Two of the
    great debugging tools I have discovered are sleep and alcohol. Without
    seeing your code, it is not possible to give advice. I have solved many
    problems just by putting the problem to bed for a while, and come back to it
    when ones' emotional state has changed. Cheers


    Comment

    • Tom Van den Brandt

      #3
      Re: Service executes twice

      Well,

      I had some sleep in the meantime...
      And this is what I came up with:
      I had the code to write to the application event log in OnStart double.
      So part of the problem is corrected. Still, the FilesSystemWatc her
      seems to fire twice. Maybe I don't understand its mechanics well enough.

      This is what I have in OnStart:

      Me.SMSFileWatch er.Path = Path
      Me.SMSFileWatch er.IncludeSubdi rectories = False
      Me.SMSFileWatch er.NotifyFilter = IO.NotifyFilter s.LastWrite
      Me.SMSFileWatch er.Filter = "freebee.jr n"
      Me.SMSFileWatch er.EnableRaisin gEvents = True
      AddHandler SMSFileWatcher. Changed, AddressOf OnChanged

      And this in OnChanged:

      My.Application. Log.WriteEntry( "An SMS has arrived!")
      send("An SMS has arrived")

      send passes the message to clients on the network...

      So, everytime I open the file, change it and save it, I have the "An SMS
      has arrived!" message twice in the Application event log.

      Am I doing this correctly?

      Thx!


      Tom


      Harry schreef:
      "Tom Van den Brandt" <guineapig@guin eapig.bewrote in message
      news:uJud95IIIH A.4684@TK2MSFTN GP06.phx.gbl...
      >Hi,
      >>
      >I wrote a simple windows service that includes a FileSystemWatch er.
      >After building and installing the service (installutil) I notice that
      >the service executes twice. I included a write to the application
      >eventlog in OnStart ("service has started and is ready to watch the
      >filesystem") and this results in two entries in the eventlog.
      >>
      >Also, the handler for the FileSystemWatch er seems to be fired twice if
      >something happens with a file the service is watching.
      >>
      >I checked the machines services and in the task manager but I see only
      >one instance of the service running.
      >>
      >I'm a newbie at this, so I probably missed something obvious... Could
      >this be the properties of the service that were not correctly configured?
      >>
      >Any ideas?
      >>
      >Thx,
      >>
      >Tom
      >
      Tom, often we look at code and miss that what we are trying to accomplish is
      often sabotaged by lack of observation or object/control events. Two of the
      great debugging tools I have discovered are sleep and alcohol. Without
      seeing your code, it is not possible to give advice. I have solved many
      problems just by putting the problem to bed for a while, and come back to it
      when ones' emotional state has changed. Cheers
      >
      >

      Comment

      • Phill W.

        #4
        Re: Service executes twice

        Tom Van den Brandt wrote:
        Still, the FilesSystemWatc her seems to fire twice.
        Maybe I don't understand its mechanics well enough.
        >
        This is what I have in OnStart:
        >
        Me.SMSFileWatch er.Path = Path
        Me.SMSFileWatch er.IncludeSubdi rectories = False
        Me.SMSFileWatch er.NotifyFilter = IO.NotifyFilter s.LastWrite
        Me.SMSFileWatch er.Filter = "freebee.jr n"
        Me.SMSFileWatch er.EnableRaisin gEvents = True
        AddHandler SMSFileWatcher. Changed, AddressOf OnChanged
        Did you declare SMSFileWatcher "WithEvents "?

        If so, VB will have /automatically/ wired-up the OnChanged Event for you
        and your AddHandler statement will simply add /another/ handler to that
        event; it won't "undo" or "replace" an existing one.
        And this in OnChanged:
        I'm not entirely sure why but, whenever I've used the FileSystemWatch er,
        I've had to allow for multiple events in rapid succession - you seem to
        get duplicate "change" events even if the file only changes once.

        HTH,
        Phill W.

        Comment

        • Tom Van den Brandt

          #5
          Re: Service executes twice

          Phill W. schreef:
          Tom Van den Brandt wrote:
          >
          >Still, the FilesSystemWatc her seems to fire twice.
          > Maybe I don't understand its mechanics well enough.
          >>
          >This is what I have in OnStart:
          >>
          > Me.SMSFileWatch er.Path = Path
          > Me.SMSFileWatch er.IncludeSubdi rectories = False
          > Me.SMSFileWatch er.NotifyFilter = IO.NotifyFilter s.LastWrite
          > Me.SMSFileWatch er.Filter = "freebee.jr n"
          > Me.SMSFileWatch er.EnableRaisin gEvents = True
          > AddHandler SMSFileWatcher. Changed, AddressOf OnChanged
          >
          Did you declare SMSFileWatcher "WithEvents "?
          Even when I comment out the Addhandler line and the EnableRaisingEv ents
          line (and put the code in OnChanged in
          Private Sub SMSFileWatcher_ Changed
          The code is still executed twice.

          I'm thinking that for some reason the filewatcher is firing the event
          twice...

          Thx for your suggestions!
          >
          If so, VB will have /automatically/ wired-up the OnChanged Event for you
          and your AddHandler statement will simply add /another/ handler to that
          event; it won't "undo" or "replace" an existing one.
          >
          >And this in OnChanged:
          >
          I'm not entirely sure why but, whenever I've used the FileSystemWatch er,
          I've had to allow for multiple events in rapid succession - you seem to
          get duplicate "change" events even if the file only changes once.
          >
          HTH,
          Phill W.

          Comment

          Working...